diff --git a/FastGenericNew.Benchmarks/Benchmarks/CtorExprILBenchmark.cs b/FastGenericNew.Benchmarks/Benchmarks/CtorExprILBenchmark.cs new file mode 100644 index 0000000..01505c0 --- /dev/null +++ b/FastGenericNew.Benchmarks/Benchmarks/CtorExprILBenchmark.cs @@ -0,0 +1,163 @@ +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Linq.Expressions; +using System.Reflection.Emit; +using System.Runtime.CompilerServices; + +namespace FastGenericNew.Benchmarks.Benchmarks; + +public class CtorExprILBenchmark +{ + [Benchmark] + public void After() + { + FastNewIL.cctor(); + } + + [Benchmark(Baseline = true)] + public void Before() + { + FastNewExpr.cctor(); + } + + #region Expression + internal static partial class FastNewExpr + { + public static ConstructorInfo? CachedConstructor; + + public static Expression>? SourceExpression; + + public static Func? CompiledDelegate; + + public static bool IsValid; + + public static void cctor() + { + CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); + IsValid = typeof(T).IsValueType || (CachedConstructor != null && !typeof(T).IsAbstract); + SourceExpression = Expression.Lambda>((!typeof(T).IsValueType) ? ((CachedConstructor != null && !typeof(T).IsAbstract) ? ((Expression)Expression.New(CachedConstructor)) : ((Expression)Expression.Call(ThrowHelper.GetSmartThrow(), Expression.Constant(CachedConstructor, typeof(ConstructorInfo))))) : ((CachedConstructor != null) ? Expression.New(CachedConstructor) : Expression.New(typeof(T))), Array.Empty()); + CompiledDelegate = SourceExpression.Compile(); + } + } + + #endregion + + #region ILEmit + [EditorBrowsable(EditorBrowsableState.Never)] + internal sealed partial class _FastNewDynMetClosure + { + public static readonly Type[] InstanceOnlyArray = new Type[] { typeof(_FastNewDynMetClosure) }; + + public static readonly _FastNewDynMetClosure Instance = new _FastNewDynMetClosure(); + } + + + internal +#if NETFRAMEWORK +static partial class FastNewIL< +#if NET5_0_OR_GREATER +[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] +#endif + T> + { +#if NETFRAMEWORK + [EditorBrowsable(EditorBrowsableState.Never)] + internal static readonly bool _isValueTypeT = typeof(T).IsValueType; +#endif + /// + /// The constructor of with given arguments.
+ /// Could be if the constructor couldn't be found. + ///
+ public static ConstructorInfo? CachedConstructor; + + public static Func? CompiledDelegate; + + public static bool IsValid; + + public static void cctor() + { + CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); + IsValid = typeof(T).IsValueType || (FastNewIL.CachedConstructor != null && !typeof(T).IsAbstract); + CompiledDelegate = System.Linq.Expressions.Expression.Lambda>(typeof(T).IsValueType + ? (FastNewIL.CachedConstructor != null + ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(FastNewIL.CachedConstructor) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(typeof(T))) + : ((FastNewIL.CachedConstructor != null && !typeof(T).IsAbstract) + ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(FastNewIL.CachedConstructor) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(ThrowHelper.GetSmartThrow())) + , Array.Empty()).Compile(); + } + } +#else +static partial class FastNewIL< +#if NET5_0_OR_GREATER +[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] +#endif + T> + { + /// + /// The constructor of with given arguments.
+ /// Could be if the constructor couldn't be found. + ///
+ public static ConstructorInfo? CachedConstructor; + +#if NETFRAMEWORK + [EditorBrowsable(EditorBrowsableState.Never)] + internal static readonly bool _isValueTypeT = typeof(T).IsValueType; +#endif + + public static Func? CompiledDelegate; + + public static bool IsValid; + + public static void cctor() + { + CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); + IsValid = typeof(T).IsValueType || (FastNewIL.CachedConstructor != null && !typeof(T).IsAbstract); + + var dm = new DynamicMethod("", typeof(T), _FastNewDynMetClosure.InstanceOnlyArray, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(); + if (IsValid) + { + if (FastNewIL.CachedConstructor != null) + il.Emit(OpCodes.Newobj, CachedConstructor!); + else + { + il.DeclareLocal(typeof(T)); + //il.Emit(OpCodes.Ldloca_S, (short)0) + //il.Emit(OpCodes.Initobj, typeof(T)); + il.Emit(OpCodes.Ldloc_0); + } + } + else + { + il.Emit(OpCodes.Call, ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), _FastNewDynMetClosure.Instance); + } + } +#endif + #endregion + + public class DemoClass { } + + [EditorBrowsable(EditorBrowsableState.Never)] + internal static partial class ThrowHelper + { + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] + + public static MethodInfo GetSmartThrow() => typeof(ThrowHelper).GetMethod("SmartThrowImpl", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)!.MakeGenericMethod(typeof(T)); + + public static T SmartThrowImpl() + { + if (typeof(T).IsInterface) + throw new MissingMethodException($"Cannot create an instance of an interface: '{typeof(T).AssemblyQualifiedName}'"); + + if (typeof(T).IsAbstract) + throw new MissingMethodException($"Cannot create an abstract class: '{typeof(T).AssemblyQualifiedName}'"); + + throw new MissingMethodException($"No match constructor found in type: '{typeof(T).AssemblyQualifiedName}'"); + } + } +} diff --git a/FastGenericNew.Benchmarks/Program.cs b/FastGenericNew.Benchmarks/Program.cs index f02eaaa..926569c 100644 --- a/FastGenericNew.Benchmarks/Program.cs +++ b/FastGenericNew.Benchmarks/Program.cs @@ -3,6 +3,8 @@ using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Environments; +using FastGenericNew.Benchmarks.Benchmarks; + ManualConfig config = ManualConfig.Create(DefaultConfig.Instance); config.AddJob( Job.Default.WithRuntime(ClrRuntime.Net48), @@ -11,4 +13,5 @@ config.AddDiagnoser(MemoryDiagnoser.Default); -BenchmarkRunner.Run(Assembly.GetCallingAssembly(), config); \ No newline at end of file +//BenchmarkRunner.Run(Assembly.GetCallingAssembly(), config); +BenchmarkRunner.Run(config); \ No newline at end of file diff --git a/FastGenericNew.SourceGenerator/CodeGenerators/DynMetClosureGenerator.cs b/FastGenericNew.SourceGenerator/CodeGenerators/DynMetClosureGenerator.cs new file mode 100644 index 0000000..3a8bd78 --- /dev/null +++ b/FastGenericNew.SourceGenerator/CodeGenerators/DynMetClosureGenerator.cs @@ -0,0 +1,29 @@ +namespace FastGenericNew.SourceGenerator.CodeGenerators; + +public class DynMetClosureGenerator : CodeGenerator +{ + public override string Filename => "_DynMetClosure.g.cs"; + + internal const string ClassName = "_FastNewDynMetClosure"; + + internal const string InstanceOnlyArrayName = "InstanceOnlyArray"; + + internal const string InstanceName = "Instance"; + + public override CodeGenerationResult Generate(in GeneratorOptions options) + { + CodeBuilder builder = new(1536, in options); + builder.WriteFileHeader(); + builder.StartNamespace(); + builder.AppendLine(@$" + [EditorBrowsable(EditorBrowsableState.Never)] + internal sealed partial class {ClassName} + {{ + public static readonly Type[] {InstanceOnlyArrayName} = new Type[] {{ typeof({options.GlobalNSDot()}{ClassName}) }}; + + public static readonly {options.GlobalNSDot()}{ClassName} {InstanceName} = new {options.GlobalNSDot()}{ClassName}(); + }}"); + builder.EndNamespace(); + return builder.BuildAndDispose(this); + } +} \ No newline at end of file diff --git a/FastGenericNew.SourceGenerator/CodeGenerators/FastNewCoreGenerator.cs b/FastGenericNew.SourceGenerator/CodeGenerators/FastNewCoreGenerator.cs index 9394cfe..01161b5 100644 --- a/FastGenericNew.SourceGenerator/CodeGenerators/FastNewCoreGenerator.cs +++ b/FastGenericNew.SourceGenerator/CodeGenerators/FastNewCoreGenerator.cs @@ -21,7 +21,22 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) builder.StartNamespace(); builder.Indent(1); builder.AppendAccessibility(options.PublicFastNewCore); - builder.AppendLine(@$"static partial class FastNew< + + // Use Expression on .NET Framework + // Use ILGenerator on .NET Core + const string UseExpressionCondition = "NETFRAMEWORK"; + + #region Get CompiledDelegateName Type + string compiledDelegateTypeNoParam; + { + CodeBuilder internalBuilder = new(32, in options); + internalBuilder.UseGenericDelegate(0); + compiledDelegateTypeNoParam = internalBuilder.ToString(); + } + #endregion + builder.Pre_If(UseExpressionCondition); + #region Expression + builder.AppendLine(@$"static partial class {ClassName}< #if NET5_0_OR_GREATER {options.DynamicallyAccessedMembers(0)} #endif @@ -31,28 +46,75 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) [EditorBrowsable(EditorBrowsableState.Never)] internal static readonly bool _isValueTypeT = typeof(T).IsValueType; #endif - /// /// The constructor of with given arguments.
/// Could be if the constructor couldn't be found. ///
public static readonly ConstructorInfo? {ConsructorName} = typeof(T).GetConstructor({(options.NonPublicConstructorSupport - ? "BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic" - : "BindingFlags.Instance | BindingFlags.Public")}, null, Type.EmptyTypes, null); +? "BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic" +: "BindingFlags.Instance | BindingFlags.Public")}, null, Type.EmptyTypes, null); - {(options.PublicSourceExpression ? "public" : "internal")} static readonly System.Linq.Expressions.Expression> SourceExpression = System.Linq.Expressions.Expression.Lambda>(typeof(T).IsValueType + {(options.PublicCompiledDelegate ? "public" : "internal")} static readonly Func {CompiledDelegateName} = System.Linq.Expressions.Expression.Lambda>(typeof(T).IsValueType ? ({options.GlobalNSDot()}{ClassName}.{ConsructorName} != null ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New({options.GlobalNSDot()}{ClassName}.{ConsructorName}) : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(typeof(T))) : (({options.GlobalNSDot()}{ClassName}.{ConsructorName} != null && !typeof(T).IsAbstract) ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New({options.GlobalNSDot()}{ClassName}.{ConsructorName}) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call({options.GlobalNSDot()}{ThrowHelperGenerator.ClassName}.GetSmartThrow(), System.Linq.Expressions.Expression.Constant({options.GlobalNSDot()}{ClassName}.{ConsructorName}, typeof(ConstructorInfo)))) - , Array.Empty()); + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call({options.GlobalNSDot()}{ThrowHelperGenerator.ClassName}.GetSmartThrow())) + , Array.Empty()).Compile(); + + public static readonly bool {IsValidName} = typeof(T).IsValueType || ({options.GlobalNSDot()}{ClassName}.{ConsructorName} != null && !typeof(T).IsAbstract); + }}"); + #endregion + builder.Pre_Else(); + #region IL + builder.AppendLine(@$"static partial class {ClassName}< +#if NET5_0_OR_GREATER +{options.DynamicallyAccessedMembers(0)} +#endif +T> + {{ + /// + /// The constructor of with given arguments.
+ /// Could be if the constructor couldn't be found. + ///
+ public static readonly ConstructorInfo? {ConsructorName} = typeof(T).GetConstructor({(options.NonPublicConstructorSupport ? "BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic" : "BindingFlags.Instance | BindingFlags.Public")}, null, Type.EmptyTypes, null); + +#if NETFRAMEWORK + [EditorBrowsable(EditorBrowsableState.Never)] + internal static readonly bool _isValueTypeT = typeof(T).IsValueType; +#endif - {(options.PublicCompiledDelegate ? "public" : "internal")} static readonly Func {CompiledDelegateName} = SourceExpression.Compile(); + {(options.PublicCompiledDelegate ? "public" : "internal")} static readonly {compiledDelegateTypeNoParam} {CompiledDelegateName}; public static readonly bool {IsValidName} = typeof(T).IsValueType || ({options.GlobalNSDot()}{ClassName}.{ConsructorName} != null && !typeof(T).IsAbstract); + + static {ClassName}() + {{ + var dm = new DynamicMethod("""", typeof(T), {options.GlobalNSDot()}{DynMetClosureGenerator.ClassName}.{DynMetClosureGenerator.InstanceOnlyArrayName}, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(); + if ({IsValidName}) + {{ + if ({options.GlobalNSDot()}{ClassName}.{ConsructorName} != null) + il.Emit(OpCodes.Newobj, {ConsructorName}!); + else + {{ + il.DeclareLocal(typeof(T)); + //il.Emit(OpCodes.Ldloca_S, (short)0) + //il.Emit(OpCodes.Initobj, typeof(T)); + il.Emit(OpCodes.Ldloc_0); + }} + }} + else + {{ + il.Emit(OpCodes.Call, {options.GlobalNSDot()}{ThrowHelperGenerator.ClassName}.GetSmartThrow()); + }} + il.Emit(OpCodes.Ret); + {CompiledDelegateName} = ({compiledDelegateTypeNoParam})dm.CreateDelegate(typeof({compiledDelegateTypeNoParam}), {options.GlobalNSDot()}{DynMetClosureGenerator.ClassName}.{DynMetClosureGenerator.InstanceName}); + }} }}"); + #endregion + builder.Pre_EndIf(); for (int parameterIndex = 1; parameterIndex <= options.MaxParameterCount; parameterIndex++) { @@ -66,7 +128,7 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) builder.StartBlock(1); - #region MyRegion + #region CachedConstructor builder.XmlDoc(2, @" /// /// The constructor of with given arguments.
@@ -103,13 +165,6 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) builder.AppendLine(", null);"); #endregion - builder.Indent(2); - builder.AppendAccessibility(options.PublicSourceExpression); - builder.Append("static readonly System.Linq.Expressions.Expression<"); - builder.UseGenericDelegate(parameterIndex); - builder.AppendLine("> SourceExpression;"); - builder.PrettyNewLine(); - builder.Indent(2); builder.AppendAccessibility(options.PublicCompiledDelegate); builder.Append("static readonly "); @@ -123,25 +178,16 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) #region Constructor builder.Indent(2); - builder.AppendLine("static FastNew()"); + builder.AppendLine($"static {ClassName}()"); builder.StartBlock(2); - /* - #region Var constructor - builder.Indent(3); - builder.Append("var constructor = "); - builder.GlobalNamespaceDot(); - builder.Append(ClassName); - builder.UseGenericMember(parameterIndex); - builder.AppendLine($".{ConsructorName};"); - #endregion - */ - #region IsValid - builder.Indent(3); - builder.AppendLine($"IsValid = {ConsructorName} != null && !typeof(T).IsAbstract;"); + builder.AppendLine(3, $"IsValid = {ConsructorName} != null && !typeof(T).IsAbstract;"); #endregion + builder.Pre_If(UseExpressionCondition); + #region Expression + #region Parameters for (int i = 0; i < parameterIndex; i++) { @@ -154,20 +200,13 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) } #endregion - #region Final builder.Indent(3); - builder.Append($"{CompiledDelegateName} = (SourceExpression = System.Linq.Expressions.Expression.Lambda<"); + builder.Append($"{CompiledDelegateName} = (System.Linq.Expressions.Expression.Lambda<"); builder.UseGenericDelegate(parameterIndex); builder.AppendLine($">({IsValidName}"); builder.Indent(4); builder.Append($"? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New({ConsructorName}!"); - /* - builder.GlobalNamespaceDot(); - builder.Append(ConstructorOfGenerator.ClassName); - builder.UseGenericMember(parameterIndex); - builder.Append($".{ConstructorOfGenerator.ValueName}"); - */ for (int i = 0; i < parameterIndex; i++) { builder.Append(',', ' '); @@ -178,9 +217,7 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) builder.Indent(4); builder.Append(": (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call("); builder.GlobalNamespaceDot(); - builder.Append($"{ThrowHelperGenerator.ClassName}.GetSmartThrow(), "); - builder.Append($"System.Linq.Expressions.Expression.Constant({ConsructorName}, typeof(ConstructorInfo))"); - builder.AppendLine(')'); + builder.AppendLine($"{ThrowHelperGenerator.ClassName}.GetSmartThrow())"); builder.Indent(3); builder.Append(", new System.Linq.Expressions.ParameterExpression[] { "); @@ -193,8 +230,67 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) builder.AppendGenericMethodArgumentName(i); } builder.AppendLine(" })).Compile();"); + #endregion + builder.Pre_Else(); + #region IL + #region Final + builder.Append(3, $@"var dm = new DynamicMethod("""", typeof(T), new Type[] {{ typeof({options.GlobalNSDot()}{DynMetClosureGenerator.ClassName}), "); + for (int i = 0; i < parameterIndex; i++) + { + if (i != 0) + { + builder.Append(',', ' '); + } + builder.Append("typeof("); + builder.AppendGenericArgumentName(i); + builder.Append(')'); + } + builder.Append(' ', '}'); + builder.AppendLine(@", restrictedSkipVisibility: true);"); + // 5 = Newobj + Ret + // +4 is required because EnsureCapacity() in il.Emit needs at least 3 bytes more available in buffer. + // TODO: more optimization is needed here. + builder.AppendLine(3, $"var il = dm.GetILGenerator({5 + parameterIndex + 4});"); + + builder.AppendLine(3, $"if ({IsValidName})"); + builder.AppendLine(3, $"{{"); + #region Parameters + for (int i = 0; i < parameterIndex; i++) + { + var actual = i + 1; + builder.Append(4, "il.Emit("); + builder.Append(actual switch + { + 0 => "OpCodes.Ldarg_0", + 1 => "OpCodes.Ldarg_1", + 2 => "OpCodes.Ldarg_2", + 3 => "OpCodes.Ldarg_3", + _ when actual <= 255 => $"OpCodes.Ldarg_S, (byte){actual}", + _ => $"OpCodes.Ldarg, (short){actual}", + }); + builder.Append(')', ';'); + builder.AppendLine(); + } + #endregion + builder.AppendLine(4, $"il.Emit(OpCodes.Newobj, {ConsructorName}!);"); + + builder.AppendLine(3, $"}}"); + builder.AppendLine(3, $"else"); + builder.AppendLine(3, $"{{"); + builder.AppendLine(4, $"il.Emit(OpCodes.Call, {options.GlobalNSDot()}{ThrowHelperGenerator.ClassName}.GetSmartThrow());"); + builder.AppendLine(3, $"}}"); + + builder.AppendLine(3, "il.Emit(OpCodes.Ret);"); + builder.Append(3, CompiledDelegateName); + builder.Append(" = ("); + builder.UseGenericDelegate(parameterIndex); + builder.Append(")dm.CreateDelegate(typeof("); + builder.UseGenericDelegate(parameterIndex); + builder.AppendLine($"), {options.GlobalNSDot()}{DynMetClosureGenerator.ClassName}.{DynMetClosureGenerator.InstanceName});"); + #endregion #endregion + builder.Pre_EndIf(); builder.EndBlock(2); #endregion @@ -210,6 +306,5 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) => base.ShouldUpdate(oldValue, newValue) || oldValue.ForceFastNewDelegate != newValue.ForceFastNewDelegate - || oldValue.PublicSourceExpression != newValue.PublicSourceExpression || oldValue.PublicCompiledDelegate != newValue.PublicCompiledDelegate; } \ No newline at end of file diff --git a/FastGenericNew.SourceGenerator/CodeGenerators/ThrowHelperGenerator.cs b/FastGenericNew.SourceGenerator/CodeGenerators/ThrowHelperGenerator.cs index 468a31b..2278898 100644 --- a/FastGenericNew.SourceGenerator/CodeGenerators/ThrowHelperGenerator.cs +++ b/FastGenericNew.SourceGenerator/CodeGenerators/ThrowHelperGenerator.cs @@ -6,6 +6,8 @@ public class ThrowHelperGenerator : CodeGenerator internal const string ClassName = "ThrowHelper"; + internal const string SmartThrowName = "SmartThrowImpl"; + public override CodeGenerationResult Generate(in GeneratorOptions options) { CodeBuilder builder = new(2048, in options); @@ -15,7 +17,7 @@ public override CodeGenerationResult Generate(in GeneratorOptions options) [EditorBrowsable(EditorBrowsableState.Never)] internal static partial class ThrowHelper {{ - [MethodImpl(MethodImplOptions.NoInlining)]"); + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]"); if (options.Trimmable) builder.AppendLine(@$" #if NET5_0_OR_GREATER @@ -24,18 +26,17 @@ internal static partial class ThrowHelper builder.AppendLine(@$" public static System.Reflection.MethodInfo GetSmartThrow() => typeof({options.GlobalNSDot()}ThrowHelper).GetMethod(""SmartThrowImpl"", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)!.MakeGenericMethod(typeof(T)); - public static T SmartThrowImpl(ConstructorInfo? constructor) + public static T SmartThrowImpl() {{ + var qualifiedName = typeof(T).AssemblyQualifiedName; + if (typeof(T).IsInterface) - throw new System.MissingMethodException($""Cannot create an instance of an interface: '{{typeof(T).AssemblyQualifiedName}}'""); + throw new System.MissingMethodException($""Cannot create an instance of an interface: '{{ qualifiedName }}'""); if (typeof(T).IsAbstract) - throw new System.MissingMethodException($""Cannot create an abstract class: '{{typeof(T).AssemblyQualifiedName}}'""); - - if (constructor == null && !typeof(T).IsValueType) - throw new System.MissingMethodException($""No match constructor found in type: '{{typeof(T).AssemblyQualifiedName}}'""); + throw new System.MissingMethodException($""Cannot create an abstract class: '{{ qualifiedName }}'""); - throw new System.MissingMethodException($""Unknown Error""); + throw new System.MissingMethodException($""No match constructor found in type: '{{ qualifiedName }}'""); }} }}"); builder.EndNamespace(); diff --git a/FastGenericNew.SourceGenerator/GeneratorOptions.cs b/FastGenericNew.SourceGenerator/GeneratorOptions.cs index 17b1752..96ababf 100644 --- a/FastGenericNew.SourceGenerator/GeneratorOptions.cs +++ b/FastGenericNew.SourceGenerator/GeneratorOptions.cs @@ -6,8 +6,6 @@ public readonly record struct GeneratorOptions public bool PublicFastNewCore { get; } - public bool PublicSourceExpression { get; } - public bool GenerateTryCreateInstance { get; } //public bool GenerateTypeTryCreateInstance { get; } @@ -44,7 +42,6 @@ public GeneratorOptions(AnalyzerConfigOptionsProvider? provider) GenerateTryCreateInstance = options.GetOrDefault(nameof(GenerateTryCreateInstance), true); GenerateCreateInstance = options.GetOrDefault(nameof(GenerateCreateInstance), true); - PublicSourceExpression = options.GetOrDefault(nameof(PublicSourceExpression), false); PublicCompiledDelegate = options.GetOrDefault(nameof(PublicCompiledDelegate), true); NonPublicConstructorSupport = options.GetOrDefault(nameof(NonPublicConstructorSupport), true); Namespace = options.GetOrDefault(nameof(Namespace), "FastGenericNew"); diff --git a/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.Misc.cs b/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.Misc.cs index 1dabfab..77a4c8f 100644 --- a/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.Misc.cs +++ b/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.Misc.cs @@ -20,6 +20,7 @@ public void WriteFileHeader() using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using System.Reflection.Emit; using System.ComponentModel; "); } diff --git a/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.cs b/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.cs index cc64e55..0a87553 100644 --- a/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.cs +++ b/FastGenericNew.SourceGenerator/Utilities/CodeBuilder.cs @@ -163,6 +163,12 @@ public void Append(char value, char value2) _length += 2; } + public void Append(int indent, string value) + { + Indent(indent); + Append(value.AsSpan()); + } + public void Append(string value) => Append(value.AsSpan()); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -187,6 +193,12 @@ public void AppendLine(char value) _length += 2; } + public void AppendLine(int indent, string value) + { + Indent(indent); + AppendLine(value.AsSpan()); + } + public void AppendLine(string value) => AppendLine(value.AsSpan()); public void AppendLine(ReadOnlySpan value) diff --git a/FastGenericNew/FastGenericNew.csproj b/FastGenericNew/FastGenericNew.csproj index 84ee37f..d365567 100644 --- a/FastGenericNew/FastGenericNew.csproj +++ b/FastGenericNew/FastGenericNew.csproj @@ -5,7 +5,7 @@ net6.0;netstandard2.0;netstandard2.1;net5.0 $(TargetFrameworks);net461 8.0 - enabled + disabled enable true true @@ -39,9 +39,13 @@ - + + + + + diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/ConstructorCache.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/ConstructorCache.g.cs deleted file mode 100644 index 4327d27..0000000 --- a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/ConstructorCache.g.cs +++ /dev/null @@ -1,321 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by FastGenericNew.SourceGenerator -// Please do not modify this file directly -// -//------------------------------------------------------------------------------ -#nullable enable -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using System.ComponentModel; - -namespace @FastGenericNew -{ - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - typeof(TArg9), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - typeof(TArg9), - typeof(TArg10), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - typeof(TArg9), - typeof(TArg10), - typeof(TArg11), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - typeof(TArg9), - typeof(TArg10), - typeof(TArg11), - typeof(TArg12), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - typeof(TArg9), - typeof(TArg10), - typeof(TArg11), - typeof(TArg12), - typeof(TArg13), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - typeof(TArg9), - typeof(TArg10), - typeof(TArg11), - typeof(TArg12), - typeof(TArg13), - typeof(TArg14), - }, null); - } - partial class FastNew - { - /// - /// The constructor of with given arguments.
- /// Could be if the constructor couldn't be found. - ///
- public static readonly ConstructorInfo? Constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] - { - typeof(TArg0), - typeof(TArg1), - typeof(TArg2), - typeof(TArg3), - typeof(TArg4), - typeof(TArg5), - typeof(TArg6), - typeof(TArg7), - typeof(TArg8), - typeof(TArg9), - typeof(TArg10), - typeof(TArg11), - typeof(TArg12), - typeof(TArg13), - typeof(TArg14), - typeof(TArg15), - }, null); - } -} diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.CreateInstance.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.CreateInstance.g.cs index 51b4f19..6fab1ce 100644 --- a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.CreateInstance.g.cs +++ b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.CreateInstance.g.cs @@ -10,6 +10,7 @@ using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using System.Reflection.Emit; using System.ComponentModel; namespace @FastGenericNew diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.TryCreateInstance.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.TryCreateInstance.g.cs index 622056a..5682244 100644 --- a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.TryCreateInstance.g.cs +++ b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew.TryCreateInstance.g.cs @@ -10,6 +10,7 @@ using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using System.Reflection.Emit; using System.ComponentModel; namespace @FastGenericNew diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew{T}.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew{T}.g.cs index 58c3eaf..0ccaedb 100644 --- a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew{T}.g.cs +++ b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/FastNew{T}.g.cs @@ -10,11 +10,14 @@ using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using System.Reflection.Emit; using System.ComponentModel; namespace @FastGenericNew { - internal static partial class FastNew< + internal +#if NETFRAMEWORK +static partial class FastNew< #if NET5_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] #endif @@ -24,26 +27,70 @@ internal static partial class FastNew< [EditorBrowsable(EditorBrowsableState.Never)] internal static readonly bool _isValueTypeT = typeof(T).IsValueType; #endif - /// /// The constructor of with given arguments.
/// Could be if the constructor couldn't be found. ///
public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression = System.Linq.Expressions.Expression.Lambda>(typeof(T).IsValueType + public static readonly Func CompiledDelegate = System.Linq.Expressions.Expression.Lambda>(typeof(T).IsValueType ? (global::@FastGenericNew.FastNew.CachedConstructor != null ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(global::@FastGenericNew.FastNew.CachedConstructor) : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(typeof(T))) : ((global::@FastGenericNew.FastNew.CachedConstructor != null && !typeof(T).IsAbstract) ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(global::@FastGenericNew.FastNew.CachedConstructor) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(global::@FastGenericNew.FastNew.CachedConstructor, typeof(ConstructorInfo)))) - , Array.Empty()); + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow())) + , Array.Empty()).Compile(); + + public static readonly bool IsValid = typeof(T).IsValueType || (global::@FastGenericNew.FastNew.CachedConstructor != null && !typeof(T).IsAbstract); + } +#else +static partial class FastNew< +#if NET5_0_OR_GREATER +[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] +#endif +T> + { + /// + /// The constructor of with given arguments.
+ /// Could be if the constructor couldn't be found. + ///
+ public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); + +#if NETFRAMEWORK + [EditorBrowsable(EditorBrowsableState.Never)] + internal static readonly bool _isValueTypeT = typeof(T).IsValueType; +#endif - public static readonly Func CompiledDelegate = SourceExpression.Compile(); + public static readonly Func CompiledDelegate; public static readonly bool IsValid = typeof(T).IsValueType || (global::@FastGenericNew.FastNew.CachedConstructor != null && !typeof(T).IsAbstract); + + static FastNew() + { + var dm = new DynamicMethod("", typeof(T), global::@FastGenericNew._FastNewDynMetClosure.InstanceOnlyArray, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(); + if (IsValid) + { + if (global::@FastGenericNew.FastNew.CachedConstructor != null) + il.Emit(OpCodes.Newobj, CachedConstructor!); + else + { + il.DeclareLocal(typeof(T)); + //il.Emit(OpCodes.Ldloca_S, (short)0) + //il.Emit(OpCodes.Initobj, typeof(T)); + il.Emit(OpCodes.Ldloc_0); + } + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); + } } +#endif internal static partial class FastNew< #if NET5_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] @@ -58,8 +105,6 @@ internal static partial class FastNew< { typeof(TArg0), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -67,11 +112,27 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(10); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -89,8 +150,6 @@ internal static partial class FastNew< typeof(TArg0), typeof(TArg1), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -98,12 +157,29 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(11); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -122,8 +198,6 @@ internal static partial class FastNew< typeof(TArg1), typeof(TArg2), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -131,13 +205,31 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(12); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -157,8 +249,6 @@ internal static partial class FastNew< typeof(TArg2), typeof(TArg3), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -166,14 +256,33 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); var p3 = System.Linq.Expressions.Expression.Parameter(typeof(TArg3)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(13); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -194,8 +303,6 @@ internal static partial class FastNew< typeof(TArg3), typeof(TArg4), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -203,15 +310,35 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); var p3 = System.Linq.Expressions.Expression.Parameter(typeof(TArg3)); var p4 = System.Linq.Expressions.Expression.Parameter(typeof(TArg4)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(14); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -233,8 +360,6 @@ internal static partial class FastNew< typeof(TArg4), typeof(TArg5), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -242,16 +367,37 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); var p3 = System.Linq.Expressions.Expression.Parameter(typeof(TArg3)); var p4 = System.Linq.Expressions.Expression.Parameter(typeof(TArg4)); var p5 = System.Linq.Expressions.Expression.Parameter(typeof(TArg5)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(15); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -274,8 +420,6 @@ internal static partial class FastNew< typeof(TArg5), typeof(TArg6), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -283,6 +427,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -290,10 +435,31 @@ static FastNew() var p4 = System.Linq.Expressions.Expression.Parameter(typeof(TArg4)); var p5 = System.Linq.Expressions.Expression.Parameter(typeof(TArg5)); var p6 = System.Linq.Expressions.Expression.Parameter(typeof(TArg6)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(16); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -317,8 +483,6 @@ internal static partial class FastNew< typeof(TArg6), typeof(TArg7), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -326,6 +490,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -334,10 +499,32 @@ static FastNew() var p5 = System.Linq.Expressions.Expression.Parameter(typeof(TArg5)); var p6 = System.Linq.Expressions.Expression.Parameter(typeof(TArg6)); var p7 = System.Linq.Expressions.Expression.Parameter(typeof(TArg7)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(17); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -362,8 +549,6 @@ internal static partial class FastNew< typeof(TArg7), typeof(TArg8), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -371,6 +556,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -380,10 +566,33 @@ static FastNew() var p6 = System.Linq.Expressions.Expression.Parameter(typeof(TArg6)); var p7 = System.Linq.Expressions.Expression.Parameter(typeof(TArg7)); var p8 = System.Linq.Expressions.Expression.Parameter(typeof(TArg8)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(18); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -409,8 +618,6 @@ internal static partial class FastNew< typeof(TArg8), typeof(TArg9), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -418,6 +625,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -428,10 +636,34 @@ static FastNew() var p7 = System.Linq.Expressions.Expression.Parameter(typeof(TArg7)); var p8 = System.Linq.Expressions.Expression.Parameter(typeof(TArg8)); var p9 = System.Linq.Expressions.Expression.Parameter(typeof(TArg9)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8), typeof(TArg9) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(19); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Ldarg_S, (byte)10); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -458,8 +690,6 @@ internal static partial class FastNew< typeof(TArg9), typeof(TArg10), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -467,6 +697,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -478,10 +709,35 @@ static FastNew() var p8 = System.Linq.Expressions.Expression.Parameter(typeof(TArg8)); var p9 = System.Linq.Expressions.Expression.Parameter(typeof(TArg9)); var p10 = System.Linq.Expressions.Expression.Parameter(typeof(TArg10)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8), typeof(TArg9), typeof(TArg10) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(20); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Ldarg_S, (byte)10); + il.Emit(OpCodes.Ldarg_S, (byte)11); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -509,8 +765,6 @@ internal static partial class FastNew< typeof(TArg10), typeof(TArg11), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -518,6 +772,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -530,10 +785,36 @@ static FastNew() var p9 = System.Linq.Expressions.Expression.Parameter(typeof(TArg9)); var p10 = System.Linq.Expressions.Expression.Parameter(typeof(TArg10)); var p11 = System.Linq.Expressions.Expression.Parameter(typeof(TArg11)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8), typeof(TArg9), typeof(TArg10), typeof(TArg11) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(21); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Ldarg_S, (byte)10); + il.Emit(OpCodes.Ldarg_S, (byte)11); + il.Emit(OpCodes.Ldarg_S, (byte)12); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -562,8 +843,6 @@ internal static partial class FastNew< typeof(TArg11), typeof(TArg12), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -571,6 +850,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -584,10 +864,37 @@ static FastNew() var p10 = System.Linq.Expressions.Expression.Parameter(typeof(TArg10)); var p11 = System.Linq.Expressions.Expression.Parameter(typeof(TArg11)); var p12 = System.Linq.Expressions.Expression.Parameter(typeof(TArg12)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8), typeof(TArg9), typeof(TArg10), typeof(TArg11), typeof(TArg12) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(22); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Ldarg_S, (byte)10); + il.Emit(OpCodes.Ldarg_S, (byte)11); + il.Emit(OpCodes.Ldarg_S, (byte)12); + il.Emit(OpCodes.Ldarg_S, (byte)13); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -617,8 +924,6 @@ internal static partial class FastNew< typeof(TArg12), typeof(TArg13), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -626,6 +931,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -640,10 +946,38 @@ static FastNew() var p11 = System.Linq.Expressions.Expression.Parameter(typeof(TArg11)); var p12 = System.Linq.Expressions.Expression.Parameter(typeof(TArg12)); var p13 = System.Linq.Expressions.Expression.Parameter(typeof(TArg13)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8), typeof(TArg9), typeof(TArg10), typeof(TArg11), typeof(TArg12), typeof(TArg13) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(23); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Ldarg_S, (byte)10); + il.Emit(OpCodes.Ldarg_S, (byte)11); + il.Emit(OpCodes.Ldarg_S, (byte)12); + il.Emit(OpCodes.Ldarg_S, (byte)13); + il.Emit(OpCodes.Ldarg_S, (byte)14); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -674,8 +1008,6 @@ internal static partial class FastNew< typeof(TArg13), typeof(TArg14), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -683,6 +1015,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -698,10 +1031,39 @@ static FastNew() var p12 = System.Linq.Expressions.Expression.Parameter(typeof(TArg12)); var p13 = System.Linq.Expressions.Expression.Parameter(typeof(TArg13)); var p14 = System.Linq.Expressions.Expression.Parameter(typeof(TArg14)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8), typeof(TArg9), typeof(TArg10), typeof(TArg11), typeof(TArg12), typeof(TArg13), typeof(TArg14) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(24); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Ldarg_S, (byte)10); + il.Emit(OpCodes.Ldarg_S, (byte)11); + il.Emit(OpCodes.Ldarg_S, (byte)12); + il.Emit(OpCodes.Ldarg_S, (byte)13); + il.Emit(OpCodes.Ldarg_S, (byte)14); + il.Emit(OpCodes.Ldarg_S, (byte)15); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } internal static partial class FastNew< @@ -733,8 +1095,6 @@ internal static partial class FastNew< typeof(TArg14), typeof(TArg15), }, null); - public static readonly System.Linq.Expressions.Expression> SourceExpression; - public static readonly Func CompiledDelegate; public static readonly bool IsValid; @@ -742,6 +1102,7 @@ internal static partial class FastNew< static FastNew() { IsValid = CachedConstructor != null && !typeof(T).IsAbstract; +#if NETFRAMEWORK var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0)); var p1 = System.Linq.Expressions.Expression.Parameter(typeof(TArg1)); var p2 = System.Linq.Expressions.Expression.Parameter(typeof(TArg2)); @@ -758,10 +1119,40 @@ static FastNew() var p13 = System.Linq.Expressions.Expression.Parameter(typeof(TArg13)); var p14 = System.Linq.Expressions.Expression.Parameter(typeof(TArg14)); var p15 = System.Linq.Expressions.Expression.Parameter(typeof(TArg15)); - CompiledDelegate = (SourceExpression = System.Linq.Expressions.Expression.Lambda>(IsValid + CompiledDelegate = (System.Linq.Expressions.Expression.Lambda>(IsValid ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(CachedConstructor!, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15) - : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow(), System.Linq.Expressions.Expression.Constant(CachedConstructor, typeof(ConstructorInfo))) + : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow()) , new System.Linq.Expressions.ParameterExpression[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15 })).Compile(); +#else + var dm = new DynamicMethod("", typeof(T), new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure), typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6), typeof(TArg7), typeof(TArg8), typeof(TArg9), typeof(TArg10), typeof(TArg11), typeof(TArg12), typeof(TArg13), typeof(TArg14), typeof(TArg15) }, restrictedSkipVisibility: true); + var il = dm.GetILGenerator(25); + if (IsValid) + { + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldarg_2); + il.Emit(OpCodes.Ldarg_3); + il.Emit(OpCodes.Ldarg_S, (byte)4); + il.Emit(OpCodes.Ldarg_S, (byte)5); + il.Emit(OpCodes.Ldarg_S, (byte)6); + il.Emit(OpCodes.Ldarg_S, (byte)7); + il.Emit(OpCodes.Ldarg_S, (byte)8); + il.Emit(OpCodes.Ldarg_S, (byte)9); + il.Emit(OpCodes.Ldarg_S, (byte)10); + il.Emit(OpCodes.Ldarg_S, (byte)11); + il.Emit(OpCodes.Ldarg_S, (byte)12); + il.Emit(OpCodes.Ldarg_S, (byte)13); + il.Emit(OpCodes.Ldarg_S, (byte)14); + il.Emit(OpCodes.Ldarg_S, (byte)15); + il.Emit(OpCodes.Ldarg_S, (byte)16); + il.Emit(OpCodes.Newobj, CachedConstructor!); + } + else + { + il.Emit(OpCodes.Call, global::@FastGenericNew.ThrowHelper.GetSmartThrow()); + } + il.Emit(OpCodes.Ret); + CompiledDelegate = (Func)dm.CreateDelegate(typeof(Func), global::@FastGenericNew._FastNewDynMetClosure.Instance); +#endif } } } diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/ThrowHelper.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/ThrowHelper.g.cs index 4f9ba1d..6486024 100644 --- a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/ThrowHelper.g.cs +++ b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/ThrowHelper.g.cs @@ -10,6 +10,7 @@ using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using System.Reflection.Emit; using System.ComponentModel; namespace @FastGenericNew @@ -18,7 +19,7 @@ namespace @FastGenericNew [EditorBrowsable(EditorBrowsableState.Never)] internal static partial class ThrowHelper { - [MethodImpl(MethodImplOptions.NoInlining)] + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] #if NET5_0_OR_GREATER [DynamicDependency("SmartThrowImpl``1()", typeof(global::@FastGenericNew.ThrowHelper))] @@ -26,18 +27,17 @@ internal static partial class ThrowHelper public static System.Reflection.MethodInfo GetSmartThrow() => typeof(global::@FastGenericNew.ThrowHelper).GetMethod("SmartThrowImpl", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)!.MakeGenericMethod(typeof(T)); - public static T SmartThrowImpl(ConstructorInfo? constructor) + public static T SmartThrowImpl() { + var qualifiedName = typeof(T).AssemblyQualifiedName; + if (typeof(T).IsInterface) - throw new System.MissingMethodException($"Cannot create an instance of an interface: '{typeof(T).AssemblyQualifiedName}'"); + throw new System.MissingMethodException($"Cannot create an instance of an interface: '{ qualifiedName }'"); if (typeof(T).IsAbstract) - throw new System.MissingMethodException($"Cannot create an abstract class: '{typeof(T).AssemblyQualifiedName}'"); - - if (constructor == null && !typeof(T).IsValueType) - throw new System.MissingMethodException($"No match constructor found in type: '{typeof(T).AssemblyQualifiedName}'"); + throw new System.MissingMethodException($"Cannot create an abstract class: '{ qualifiedName }'"); - throw new System.MissingMethodException($"Unknown Error"); + throw new System.MissingMethodException($"No match constructor found in type: '{ qualifiedName }'"); } } } diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/TypeNew.CreateInstance.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/TypeNew.CreateInstance.g.cs index 0752037..af59c82 100644 --- a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/TypeNew.CreateInstance.g.cs +++ b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/TypeNew.CreateInstance.g.cs @@ -10,6 +10,7 @@ using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using System.Reflection.Emit; using System.ComponentModel; namespace @FastGenericNew diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/_DynMetClosure.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/_DynMetClosure.g.cs new file mode 100644 index 0000000..22e2002 --- /dev/null +++ b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/_DynMetClosure.g.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by FastGenericNew.SourceGenerator +// Please do not modify this file directly +// +//------------------------------------------------------------------------------ +#nullable enable +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Reflection.Emit; +using System.ComponentModel; + +namespace @FastGenericNew +{ + + [EditorBrowsable(EditorBrowsableState.Never)] + internal sealed partial class _FastNewDynMetClosure + { + public static readonly Type[] InstanceOnlyArray = new Type[] { typeof(global::@FastGenericNew._FastNewDynMetClosure) }; + + public static readonly global::@FastGenericNew._FastNewDynMetClosure Instance = new global::@FastGenericNew._FastNewDynMetClosure(); + } +} diff --git a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/_GenerationInfo.g.cs b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/_GenerationInfo.g.cs index 62748ce..b535298 100644 --- a/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/_GenerationInfo.g.cs +++ b/FastGenericNew/_generated/FastGenericNew.SourceGenerator/FastGenericNew.SourceGenerator.Generator/_GenerationInfo.g.cs @@ -9,7 +9,6 @@ MaxParameterCount = 16 PublicFastNewCore = False - PublicSourceExpression = True (default: False) GenerateTryCreateInstance = True GenerateCreateInstance = True GenerateTypeCreateInstance = True @@ -17,7 +16,7 @@ NonPublicConstructorSupport = True Namespace = FastGenericNew ForceFastNewDelegate = False - IsGeneratedHeader = True + AlertGeneratedFile = True DisableGeneratorCache = False Trimmable = True PrettyOutput = True (default: False) @@ -29,7 +28,6 @@ 16 False - True True True True @@ -37,7 +35,7 @@ True FastGenericNew False - True + True False True True