53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
|
using System.Reflection;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
Type[] s_types = Type.EmptyTypes;
|
|||
|
|
|||
|
Init();
|
|||
|
|
|||
|
var source = new StringBuilder();
|
|||
|
using var writer = new StringWriter(source);
|
|||
|
|
|||
|
foreach (Type type in s_types)
|
|||
|
{
|
|||
|
writer.WriteLine("// This file was generated by X10D.");
|
|||
|
writer.WriteLine("// Do not edit it manually.");
|
|||
|
writer.WriteLine();
|
|||
|
writer.WriteLine("namespace X10D");
|
|||
|
writer.WriteLine();
|
|||
|
writer.WriteLine("public static partial class EnumerableExtensions");
|
|||
|
writer.WriteLine("{");
|
|||
|
writer.WriteLine(" /// <summary>");
|
|||
|
writer.WriteLine($" /// Computes the product of a sequence of <see cref=\"{type.FullName}\" /> values.");
|
|||
|
writer.WriteLine(" /// </summary>");
|
|||
|
writer.WriteLine(
|
|||
|
$" /// <param name=\"source\">The sequence of <see cref=\"{type.FullName}\" /> values that are used to calculate the product.</param>");
|
|||
|
writer.WriteLine(" /// <returns>The product of the values in the sequence.</returns>");
|
|||
|
|
|||
|
if (type.GetCustomAttribute<CLSCompliantAttribute>() is { } compliant)
|
|||
|
writer.WriteLine($" [CLSCompliant({compliant.IsCompliant.ToString().ToLower()})]");
|
|||
|
|
|||
|
writer.WriteLine($" public static {type.FullName} Product(this IEnumerable<{type.FullName}> source)");
|
|||
|
writer.WriteLine(" {");
|
|||
|
writer.WriteLine(" if (source is null)");
|
|||
|
writer.WriteLine(" throw new ArgumentNullException(nameof(source));");
|
|||
|
writer.WriteLine();
|
|||
|
writer.WriteLine(" var result = 1m;");
|
|||
|
writer.WriteLine();
|
|||
|
writer.WriteLine(" foreach (var item in source)");
|
|||
|
writer.WriteLine(" result *= item;");
|
|||
|
writer.WriteLine();
|
|||
|
writer.WriteLine(" return result;");
|
|||
|
writer.WriteLine(" }");
|
|||
|
writer.WriteLine("}");
|
|||
|
}
|
|||
|
|
|||
|
return;
|
|||
|
|
|||
|
void Init()
|
|||
|
{
|
|||
|
s_types = new[]
|
|||
|
{
|
|||
|
typeof(int), typeof(uint)
|
|||
|
};
|
|||
|
}
|