Category: .NET Core

RSCG – NextGenMapper

RSCG – NextGenMapper
 
 

name NextGenMapper
nuget https://www.nuget.org/packages/NextGenMapper/
link https://github.com/DedAnton/NextGenMapper
author Anton Ryabchikov

Automating generating mapping between classes

 

This is how you can use NextGenMapper .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NextGenMapper" Version="0.1.0-alpha.13" OutputItemType="Analyzer"  />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using NextGenMapperDemo;

using NextGenMapper;

//var source = new Source("Anton", 25);

//var destination = source.Map<Destination>();

//Console.WriteLine(destination);


//record Source(string Name, int Age);
//record Destination(string Name, int Age);

Person p = new();
p.Name = "Andrei Ignat";
p.Country_Name = "Romania";

var dto = p.MapWith<PersonDTO>(
    BirthCountry:new Country()
    {
        CountryCode=p.Country_CountryCode,
        Name=p.Country_Name
    });

//Name is automatically mapped
Console.WriteLine(dto.Name);
Console.WriteLine(dto.BirthCountry!.Name);




namespace NextGenMapperDemo;

internal class Person
{
    public int ID { get; set; } 
    public string? Name { get; set; }
    public string? Country_Name { get; set; }
    public string? Country_CountryCode { get; set; }
}






namespace NextGenMapperDemo;
internal class Country
{

    public string? Name { get; set; }
    public string? CountryCode { get; set; }
}
internal class PersonDTO
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public Country? BirthCountry { get; set; }
}


 

The code that is generated is

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace NextGenMapper.Extensions
{
    internal static class MapperExtensions
    {
        /// <summary>
        /// Do not use this method, for auto-generated mapper only!
        /// </summary>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static bool TryGetSpan<TSource>(this IEnumerable<TSource> source, out ReadOnlySpan<TSource> span)
        {
            bool result = true;
            if (source.GetType() == typeof(TSource[]))
            {
                span = Unsafe.As<TSource[]>(source);
            }
            #if NET5_0_OR_GREATER
            else if (source.GetType() == typeof(List<TSource>))
            {
                span = CollectionsMarshal.AsSpan(Unsafe.As<List<TSource>>(source));
            }
            #endif
            else
            {
                span = default;
                result = false;
            }

            return result;
        }
    }
}
#nullable enable
using NextGenMapper.Extensions;

namespace NextGenMapper
{
    internal static partial class Mapper
    {
        internal static NextGenMapperDemo.PersonDTO Map<To>(this NextGenMapperDemo.Person source) => new NextGenMapperDemo.PersonDTO()
        {
            Name = source.Name
        };
    }
}
#nullable enable
using NextGenMapper.Extensions;

namespace NextGenMapper
{
    internal static partial class Mapper
    {
        internal static NextGenMapperDemo.PersonDTO MapWith<To>
        (
            this NextGenMapperDemo.Person source,
            NextGenMapperDemo.Country BirthCountry
        )
        => new NextGenMapperDemo.PersonDTO
        {
            Name = source.Name,
            BirthCountry = BirthCountry
        };
    }
}
#nullable enable
using NextGenMapper.Extensions;

namespace NextGenMapper
{
    internal static partial class Mapper
    {
        internal static NextGenMapperDemo.PersonDTO MapWith<To>
        (
            this NextGenMapperDemo.Person source,
            int Id = default!,
            string? Name = default!,
            NextGenMapperDemo.Country? BirthCountry = default!
        )
        {
            throw new System.NotImplementedException("This method is a mock and is not intended to be called");
        }
    }
}
using System;
using System.Linq;

namespace NextGenMapper
{
    internal static partial class Mapper
    {
        internal static To Map<To>(this object source) => throw new InvalidOperationException($"Error when mapping {source.GetType()} to {typeof(To)}, mapping function was not found. Create custom mapping function.");

        internal static To MapWith<To>(this object source) => throw new InvalidOperationException($"Error when mapping {source.GetType()} to {typeof(To)}, mapping function was not found. Create custom mapping function.");
    
        internal static To Project<To>(this IQueryable<object> source) => throw new InvalidOperationException($"Error when project {source.GetType()} to {typeof(To)}, project function was not found.");
        
        internal static To ProjectWith<To>(this IQueryable<object> source) => throw new InvalidOperationException($"Error when project {source.GetType()} to {typeof(To)}, project function was not found.");
        
        internal static To Project<To>(this IQueryable source) => throw new InvalidOperationException($"Error when project {source.GetType()} to {typeof(To)}, projection for non generic IQueryable is not supported");

        internal static To ProjectWith<To>(this IQueryable source) => throw new InvalidOperationException($"Error when project {source.GetType()} to {typeof(To)}, projection for non generic IQueryable is not supported");
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/NextGenMapper

RSCG – BenutomoAutomaticDisposeImplSourceGenerator

RSCG – BenutomoAutomaticDisposeImplSourceGenerator
 
 

name BenutomoAutomaticDisposeImplSourceGenerator
nuget https://www.nuget.org/packages/Benutomo.AutomaticDisposeImpl.SourceGenerator/
link https://github.com/benutomo-dev/RoslynComponents
author benutomo

Automatic dispose resources

 

This is how you can use BenutomoAutomaticDisposeImplSourceGenerator .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Benutomo.AutomaticDisposeImpl.SourceGenerator" Version="2.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    
  </ItemGroup>
	 <PropertyGroup>
        <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
        <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
    </PropertyGroup>

</Project>


The code that you will use is


using IDisposableGeneratorDemo;
//https://github.com/benutomo-dev/RoslynComponents
using (var db = new DALDB())
{
    Console.WriteLine("before releasing");
}
Console.WriteLine("after releasing");


namespace IDisposableGeneratorDemo;
using Benutomo;

[AutomaticDisposeImpl]
partial class DALDB :IDisposable
{
    [EnableAutomaticDispose]
    private readonly ConnectionDB cn;
    [EnableAutomaticDispose]
    private readonly ConnectionDB cn1;

    public DALDB()
    {
        cn = new ConnectionDB();
        cn1=new ConnectionDB();
    }
}



namespace IDisposableGeneratorDemo;

class ConnectionDB : IDisposable
{
    public void Dispose()
    {
        Console.WriteLine("disposing connectiondb");
    }
}


 

The code that is generated is

#pragma warning disable CS0436
#nullable enable

namespace Benutomo
{
    /// <summary>
    /// 指定したクラスに破棄(<see cref=""System.IDisposable"" />,<see cref=""System.IAsyncDisposable"" />)をサポートするメンバを破棄する<see cref=""System.IDisposable.Dispose"" />メソッドおよび<see cref=""System.IAsyncDisposable.DisposeAsync"" />メソッド(当該クラスに<see cref=""System.IAsyncDisposable"" />インターフェイスが含まれている場合のみ)を自動実装する。
    /// </summary>
    [global::System.AttributeUsage(global::System.AttributeTargets.Class)]
    internal class AutomaticDisposeImplAttribute : global::System.Attribute
    {
        /// <summary>
        /// 自動破棄実装の既定動作を設定する。
        /// </summary>
        public AutomaticDisposeImplMode Mode { get; set; }
    }
}
#pragma warning disable CS0436
#nullable enable

namespace Benutomo
{
    /// <summary>
    /// 破棄(<see cref=""System.IDisposable"" />,<see cref=""System.IAsyncDisposable"" />)をサポートするメンバを自動実装Disposeの対象とすることに関する振る舞いの指定。
    /// </summary>
    internal enum AutomaticDisposeImplMode
    {
        /// <summary>
        /// <see cref=""System.IDisposable"" />,<see cref=""System.IAsyncDisposable"" />を継承する型を持つメンバは暗黙的に自動Dispose呼び出しの対象となる。
        /// </summary>
        Implicit,

        /// <summary>
        /// <see cref=""System.IDisposable"" />,<see cref=""System.IAsyncDisposable"" />を継承する型を持つメンバは自動Dispose呼び出しの対象となる。
        /// </summary>
        Explicit,
    }
}
#pragma warning disable CS0436
#nullable enable

namespace Benutomo
{
    /// <summary>
    /// このメンバに対して、<see cref=""System.IDisposable.Dispose"" />メソッドまたは<see cref=""System.IAsyncDisposable.DisposeAsync"" />メソッドの自動呼出しは行いません。このオブジェクトで破棄するのが不適当であるかユーザ自身が<see cref=""System.IDisposable.Dispose"" />メソッドまたは<see cref=""System.IAsyncDisposable.DisposeAsync"" />メソッドの呼び出しを実装するメンバです。
    /// </summary>
    [global::System.AttributeUsage(global::System.AttributeTargets.Field | global::System.AttributeTargets.Property)]
    internal class DisableAutomaticDisposeAttribute : global::System.Attribute
    {
    }
}
#pragma warning disable CS0436
#nullable enable

namespace Benutomo
{
    /// <summary>
    /// このオブジェクトの破棄と同時に自動的に<see cref=""System.IDisposable.Dispose"" />メソッドまたは<see cref=""System.IAsyncDisposable.DisposeAsync"" />メソッドを呼び出します。
    /// </summary>
    [global::System.AttributeUsage(global::System.AttributeTargets.Field | global::System.AttributeTargets.Property)]
    internal class EnableAutomaticDisposeAttribute : global::System.Attribute
    {
        public EnableAutomaticDisposeAttribute() { }

        /// <summary>
        /// このオブジェクトの破棄と同時に自動的に<see cref=""System.IDisposable.Dispose"" />メソッドまたは<see cref=""System.IAsyncDisposable.DisposeAsync"" />メソッドを呼び出します。
        /// </summary>
        /// <param name=""linkedMembers"">このメンバの破棄に連動して破棄されるメンバ(ここで列挙されたメンバはEnable/DisableAutomaticDispose属性を省略可能)</param>
        public EnableAutomaticDisposeAttribute(params string[] dependencyMembers) { }
    }
}
#nullable enable
#pragma warning disable CS0612,CS0618,CS0619
namespace IDisposableGeneratorDemo
{
    partial class DALDB // This is implementation class by AutomaticDisposeImpl.
    {
        [global::System.ComponentModel.Browsable(false)]
        [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
        [global::System.Obsolete("AutomaticDisposeImplによって生成されたフィールドです。一般のコードから参照してはいけません。")]
        private const int __generator_internal_BeNotInitiatedAnyDispose = 0;
        [global::System.ComponentModel.Browsable(false)]
        [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
        [global::System.Obsolete("AutomaticDisposeImplによって生成されたフィールドです。一般のコードから参照してはいけません。")]
        private const int __generator_internal_InitiatedSyncDispose  = 1;
        [global::System.ComponentModel.Browsable(false)]
        [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
        [global::System.Obsolete("AutomaticDisposeImplによって生成されたフィールドです。一般のコードから参照してはいけません。")]
        private const int __generator_internal_InitiatedAsyncDispose = 2;
        [global::System.ComponentModel.Browsable(false)]
        [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
        [global::System.Obsolete("AutomaticDisposeImplによって生成されたフィールドです。一般のコードから参照してはいけません。")]
        private const int __generator_internal_DisposeAlreadyCompleted = 9;
        [global::System.ComponentModel.Browsable(false)]
        [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
        [global::System.Obsolete("AutomaticDisposeImplによって生成されたフィールドです。一般のコードから参照してはいけません。")]
        private int __generator_internal_disposeState = __generator_internal_BeNotInitiatedAnyDispose;

        public bool IsDisposed => (global::System.Threading.Thread.VolatileRead(ref __generator_internal_disposeState) != __generator_internal_BeNotInitiatedAnyDispose);

        [global::System.ComponentModel.Browsable(false)]
        [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
        [global::System.Obsolete("AutomaticDisposeImplによって生成されたフィールドです。一般のコードから参照してはいけません。")]
        private int __generator_internal_managedObjectDisposeState = 0;

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                var managedObjectDisposeState = global::System.Threading.Interlocked.Exchange(ref __generator_internal_managedObjectDisposeState, 1);
                if (managedObjectDisposeState == 0)
                {
                    try
                    {
                        (this.cn as global::System.IDisposable)?.Dispose();
                    }
                    catch (global::System.Exception ex)
                    {
                        global::System.Diagnostics.Debug.Fail($"Caught an exception in the cn.Dispose() calling. Message=\"{ex.Message}\"");
                    }
                    try
                    {
                        (this.cn1 as global::System.IDisposable)?.Dispose();
                    }
                    catch (global::System.Exception ex)
                    {
                        global::System.Diagnostics.Debug.Fail($"Caught an exception in the cn1.Dispose() calling. Message=\"{ex.Message}\"");
                    }
                }
            }
        }

        public void Dispose()
        {
            var dispose_state = global::System.Threading.Interlocked.CompareExchange(ref __generator_internal_disposeState, __generator_internal_InitiatedSyncDispose, __generator_internal_BeNotInitiatedAnyDispose);
            if (dispose_state == __generator_internal_BeNotInitiatedAnyDispose)
            {

                // Dispose managed members and release unmaneged resources.
                Dispose(disposing: true);

                global::System.Threading.Thread.VolatileWrite(ref __generator_internal_disposeState, __generator_internal_DisposeAlreadyCompleted);
            }
        }
    }
}

#pragma warning disable CS0436
#nullable enable

namespace Benutomo
{
    /// <summary>
    /// <see cref=""Benutomo.AutomaticDisposeImplAttribute""/>を利用しているクラスで、ユーザが実装するマネージドオブジェクトを非同期的な処理による破棄を行うメソッドに付与する。このメソッドはデストラクタからは呼び出されない。デストラクタからも呼び出される必要がある場合はデストラクタで必要な処理を全て同期的に行うようにした上で<see cref=""Benutomo.UnmanagedResourceReleaseMethodAttribute"">を使用すること。この属性を付与するメソッドは引数なしで戻り値は<see cref=""System.Threading.ValueTask"" />などawait可能な型である必要がある。このメソッドはこのオブジェクトのDisposeAsync()が初めて実行された時に自動実装コードから呼び出される。ただし、このメソッドを所有するクラスがIDisposableも実装していて、かつ、Dispose()によってこのオブジェクトが破棄された場合は、この属性が付与されているメソッドは呼び出されず、<see cref=""Benutomo.ManagedObjectDisposeMethodAttribute"">が付与されているメソッドが呼び出される。
    /// </summary>
    [global::System.AttributeUsage(global::System.AttributeTargets.Method)]
    internal class ManagedObjectAsyncDisposeMethodAttribute : global::System.Attribute
    {
        /// <summary>
        /// <inheritdoc cref=""Benutomo.ManagedObjectAsyncDisposeMethodAttribute""/>
        /// </summary>
        public ManagedObjectAsyncDisposeMethodAttribute() { }
    }
}
#pragma warning disable CS0436
#nullable enable

namespace Benutomo
{
    /// <summary>
    /// <see cref=""Benutomo.AutomaticDisposeImplAttribute""/>を利用しているクラスで、ユーザが実装するマネージドオブジェクトを同期的な処理による破棄を行うメソッドに付与する。このメソッドはデストラクタからは呼び出されない。デストラクタからも呼び出される必要がある場合は<see cref=""Benutomo.UnmanagedResourceReleaseMethodAttribute"">を使用すること。この属性を付与するメソッドは引数なしで戻り値はvoidである必要がある。このメソッドはこのオブジェクトのDispose()が初めて実行された時に自動実装コードから呼び出される。ただし、このメソッドを所有するクラスがIAsyncDisposableも実装していて、かつ、DisposeAsync()によってこのオブジェクトが破棄された場合は、この属性が付与されているメソッドは呼び出されず、<see cref=""Benutomo.ManagedObjectAsyncDisposeMethodAttribute"">が付与されているメソッドが呼び出される。
    /// </summary>
    [global::System.AttributeUsage(global::System.AttributeTargets.Method)]
    internal class ManagedObjectDisposeMethodAttribute : global::System.Attribute
    {
        /// <summary>
        /// <inheritdoc cref=""Benutomo.ManagedObjectDisposeMethodAttribute""/>
        /// </summary>
        public ManagedObjectDisposeMethodAttribute() { }
    }
}
#pragma warning disable CS0436
#nullable enable

namespace Benutomo
{
    /// <summary>
    /// <see cref=""Benutomo.AutomaticDisposeImplAttribute""/>を利用しているクラスで、ユーザが実装するアンマネージドリソースの解放を行うメソッド(引数なしで戻り値はvoid)に付与する。このメソッドはこのオブジェクトのDispose()またはDisposeAsync()、デストラクタのいずれかが初めて実行された時に自動実装コードから呼び出される。この属性を付与したメソッドは、実装者の責任でGCのファイナライズスレッドから呼び出されても問題無いように実装しなければならないことに注意すること。
    /// </summary>
    [global::System.AttributeUsage(global::System.AttributeTargets.Method)]
    internal class UnmanagedResourceReleaseMethodAttribute : global::System.Attribute
    {
        /// <summary>
        /// <inheritdoc cref=""Benutomo.UnmanagedResourceReleaseMethodAttribute""/>
        /// </summary>
        public UnmanagedResourceReleaseMethodAttribute() { }
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/BenutomoAutomaticDisposeImplSourceGenerator

RSCG – SyncMethodGenerator

RSCG – SyncMethodGenerator
 
 

name SyncMethodGenerator
nuget https://www.nuget.org/packages/Zomp.SyncMethodGenerator/
link https://github.com/zompinc/sync-method-generator
author Zomp Inc.

Generating Sync method from async

 

This is how you can use SyncMethodGenerator .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Zomp.SyncMethodGenerator" Version="1.0.14" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using Zomp.SyncMethodGeneratorDemo;

Console.WriteLine("Hello, World!");
Writer.Haha("a.txt", "Andrei Ignat");
Writer.Write("a.txt", "andrei ignat");


namespace Zomp.SyncMethodGeneratorDemo;

partial class Writer
{
    [Zomp.SyncMethodGenerator.CreateSyncVersion]
    public static async Task WriteAsync(string file, string contents,
CancellationToken ct)
    {
        await File.WriteAllTextAsync(file, contents, ct).ConfigureAwait(true);
    }
    [Zomp.SyncMethodGenerator.CreateSyncVersion]
    public static async Task HahaAsync(ReadOnlyMemory<byte> buffer, Stream stream,
CancellationToken ct)
    => await stream.WriteAsync(buffer, ct).ConfigureAwait(true);
}


 

The code that is generated is

// <auto-generated/>
namespace Zomp.SyncMethodGenerator
{
    /// <summary>
    /// An attribute that can be used to automatically generate a synchronous version of an async method. Must be used in a partial class.
    /// </summary>
    [System.AttributeUsage(System.AttributeTargets.Method)]
    internal class CreateSyncVersionAttribute : System.Attribute
    {
    }
}
// <auto-generated/>
#nullable enable
namespace Zomp.SyncMethodGeneratorDemo;
partial class Writer
{
    public static void Haha(global::System.ReadOnlySpan<byte> buffer, global::System.IO.Stream stream)
    => stream.Write(buffer);
}

// <auto-generated/>
#nullable enable
namespace Zomp.SyncMethodGeneratorDemo;
partial class Writer
{
    public static void Write(string file, string contents)
    {
        global::System.IO.File.WriteAllText(file, contents);
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/SyncMethodGenerator

RSCG – spreadcheetah

RSCG – spreadcheetah
 
 

name spreadcheetah
nuget https://www.nuget.org/packages/spreadcheetah/
link https://github.com/sveinungf/spreadcheetah
author Sveinung

generating Excel from objects

 

This is how you can use spreadcheetah .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SpreadCheetah" Version="1.10.0" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


using SpreadCheetah;
using spreadcheetahDemo;

using var stream = File.Create("a.xlsx");
using var spreadsheet = await Spreadsheet.CreateNewAsync(stream);

// A spreadsheet must contain at least one worksheet.
await spreadsheet.StartWorksheetAsync("Sheet 1");

// Cells are inserted row by row.
var row = new List<Cell>();
row.Add(new Cell("Answer to the ultimate question:"));
row.Add(new Cell(42));

// Rows are inserted from top to bottom.
await spreadsheet.AddRowAsync(row);
var p=new Person();
p.FirstName = "Andrei";
p.LastName = "Ignat";
await spreadsheet.AddAsRowAsync(p, PersonRowContext.Default.Person);

// Remember to call Finish before disposing.
// This is important to properly finalize the XLSX file.
await spreadsheet.FinishAsync();
Console.WriteLine("see a.xlsx");



using SpreadCheetah.SourceGeneration;

namespace spreadcheetahDemo;

public class Person
{
    public string? FirstName { get; set; }
    public string? LastName { get; set; }
}

[WorksheetRow(typeof(Person))]
public partial class PersonRowContext : WorksheetRowContext
{
}

 

The code that is generated is

// <auto-generated />
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace spreadcheetahDemo
{
    public partial class PersonRowContext
    {
        private static PersonRowContext? _default;
        public static PersonRowContext Default => _default ??= new PersonRowContext();

        public PersonRowContext()
        {
        }

        private WorksheetRowTypeInfo<spreadcheetahDemo.Person>? _Person;
        public WorksheetRowTypeInfo<spreadcheetahDemo.Person> Person => _Person ??= WorksheetRowMetadataServices.CreateObjectInfo<spreadcheetahDemo.Person>(AddAsRowAsync, AddRangeAsRowsAsync);

        private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, spreadcheetahDemo.Person? obj, CancellationToken token)
        {
            if (spreadsheet is null)
                throw new ArgumentNullException(nameof(spreadsheet));
            if (obj is null)
                return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);
            return AddAsRowInternalAsync(spreadsheet, obj, token);
        }

        private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<spreadcheetahDemo.Person?> objs, CancellationToken token)
        {
            if (spreadsheet is null)
                throw new ArgumentNullException(nameof(spreadsheet));
            if (objs is null)
                throw new ArgumentNullException(nameof(objs));
            return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
        }

        private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, spreadcheetahDemo.Person obj, CancellationToken token)
        {
            var cells = ArrayPool<DataCell>.Shared.Rent(2);
            try
            {
                await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
            }
            finally
            {
                ArrayPool<DataCell>.Shared.Return(cells, true);
            }
        }

        private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<spreadcheetahDemo.Person?> objs, CancellationToken token)
        {
            var cells = ArrayPool<DataCell>.Shared.Rent(2);
            try
            {
                await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
            }
            finally
            {
                ArrayPool<DataCell>.Shared.Return(cells, true);
            }
        }

        private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<spreadcheetahDemo.Person?> objs, DataCell[] cells, CancellationToken token)
        {
            foreach (var obj in objs)
            {
                await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
            }
        }

        private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, spreadcheetahDemo.Person? obj, DataCell[] cells, CancellationToken token)
        {
            if (obj is null)
                return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);

            cells[0] = new DataCell(obj.FirstName);
            cells[1] = new DataCell(obj.LastName);
            return spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token);
        }
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/spreadcheetah

RSCG – Immutype

RSCG – Immutype
 
 

name Immutype
nuget https://www.nuget.org/packages/Immutype/
link https://github.com/DevTeam/Immutype
author Nikolay Pianikov

Immutable from constructors

 

This is how you can use Immutype .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Immutype" Version="1.0.14" OutputItemType="Analyzer" >
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>

</Project>


The code that you will use is


using ImmutypeDemo;

Person p = new("Andrei","Ignat");
var p2= p.WithFirstName("Test");
Console.WriteLine(p2.LastName);


namespace ImmutypeDemo;

[Immutype.Target]
internal class Person
{
    public string? FirstName;
    public Person()
    {
    }
    public Person(string? FirstName,string LastName)
    {
        this.FirstName = FirstName;
        this.LastName = LastName;
    }
    public int ID { get; set; }
    public string? LastName { get; set;}
}


 

The code that is generated is

// ReSharper disable CheckNamespace
// ReSharper disable ClassNeverInstantiated.Global
namespace Immutype
{
    using System;
    
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor, Inherited = false)]
    public class TargetAttribute: Attribute { }
}
namespace ImmutypeDemo;

using System.Collections.Generic;
using System.Linq;
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 
internal static partial class PersonExtensions{


[System.Runtime.CompilerServices.MethodImplAttribute((System.Runtime.CompilerServices.MethodImplOptions)256),System.Diagnostics.Contracts.PureAttribute]
public static ImmutypeDemo.Person WithFirstName(this ImmutypeDemo.Person it,string? FirstName){
if( it==default(ImmutypeDemo.Person))throw new System.ArgumentNullException("it");
return new ImmutypeDemo.Person(FirstName, it.LastName );}

[System.Runtime.CompilerServices.MethodImplAttribute((System.Runtime.CompilerServices.MethodImplOptions)256),System.Diagnostics.Contracts.PureAttribute]
public static ImmutypeDemo.Person WithLastName(this ImmutypeDemo.Person it,string LastName){
if( it==default(ImmutypeDemo.Person))throw new System.ArgumentNullException("it");
if(LastName==default(string ))throw new System.ArgumentNullException("LastName");
return new ImmutypeDemo.Person( it.FirstName,LastName);}}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Immutype

RSCG – GeneratorEquals

RSCG – GeneratorEquals
 
 

name GeneratorEquals
nuget https://www.nuget.org/packages/Generator.Equals/
link https://github.com/diegofrata/Generator.Equals
author Diego Frato

Generating Equals from properties

 

This is how you can use GeneratorEquals .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Generator.Equals" Version="3.0.0" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using GeneratorEqualsDemo;
var p1 = new Person()
{
    ID = 1,
    FirstName = "Andrei",
    LastName = "Ignat"
};
var p2= new Person()
{
    ID = 2,
    FirstName = "Andrei",
    LastName = "Ignat"
};
Console.WriteLine(p1==p2);



using Generator.Equals;

namespace GeneratorEqualsDemo;

[Equatable]
partial class Person
{
    [IgnoreEquality]
    public int ID { get; set; }
    [DefaultEquality]
    public string? FirstName { get; set; }
    [DefaultEquality] 
    public string? LastName { get; set; }
}


 

The code that is generated is


#nullable enable
#pragma warning disable CS0612,CS0618
#pragma warning disable CS0436

namespace GeneratorEqualsDemo
{
    partial class Person : global::System.IEquatable<Person>
    {
        /// <summary>
        /// Indicates whether the object on the left is equal to the object on the right.
        /// </summary>
        /// <param name="left">The left object</param>
        /// <param name="right">The right object</param>
        /// <returns>true if the objects are equal; otherwise, false.</returns>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
        public static bool operator ==(
            global::GeneratorEqualsDemo.Person? left,
            global::GeneratorEqualsDemo.Person? right) =>
            global::Generator.Equals.DefaultEqualityComparer<global::GeneratorEqualsDemo.Person?>.Default
                .Equals(left, right);
        
        /// <summary>
        /// Indicates whether the object on the left is not equal to the object on the right.
        /// </summary>
        /// <param name="left">The left object</param>
        /// <param name="right">The right object</param>
        /// <returns>true if the objects are not equal; otherwise, false.</returns>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
        public static bool operator !=(global::GeneratorEqualsDemo.Person? left, global::GeneratorEqualsDemo.Person? right) =>
            !(left == right);
        
        /// <inheritdoc/>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
        public override bool Equals(object? obj) =>
            Equals(obj as global::GeneratorEqualsDemo.Person);
        
        /// <inheritdoc/>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
        bool global::System.IEquatable<global::GeneratorEqualsDemo.Person>.Equals(global::GeneratorEqualsDemo.Person? obj) => Equals((object?) obj);
        
        /// <inheritdoc/>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
        protected bool Equals(global::GeneratorEqualsDemo.Person? other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            
            return other.GetType() == this.GetType()
                && global::Generator.Equals.DefaultEqualityComparer<global::System.String?>.Default.Equals(this.FirstName!, other.FirstName!)
                && global::Generator.Equals.DefaultEqualityComparer<global::System.String?>.Default.Equals(this.LastName!, other.LastName!)
                ;
        }
        
        /// <inheritdoc/>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
        public override int GetHashCode()
        {
            var hashCode = new global::System.HashCode();
            
            hashCode.Add(this.GetType());
            hashCode.Add(
                this.FirstName!,
                global::Generator.Equals.DefaultEqualityComparer<global::System.String?>.Default);
            hashCode.Add(
                this.LastName!,
                global::Generator.Equals.DefaultEqualityComparer<global::System.String?>.Default);
            
            return hashCode.ToHashCode();
        }
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/GeneratorEquals

RSCG – FastGenericNew

RSCG – FastGenericNew
 
 

name FastGenericNew
nuget https://www.nuget.org/packages/FastGenericNew.SourceGenerator/
link https://github.com/Nyrest/FastGenericNew
author Boring3 Nyrest

Creating instances fast. As generator show source code. Otherwise could be a dll

 

This is how you can use FastGenericNew .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
	<ItemGroup>
	  <PackageReference Include="FastGenericNew.SourceGenerator" Version="3.1.0-preview1">
	    <PrivateAssets>all</PrivateAssets>
	    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
	  </PackageReference>
	</ItemGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using FastGenericNew;
using FastGenericNewDemo;

Console.WriteLine("Hello, World!");
//private constructor
var p= FastNew.CreateInstance<Person>() ;
Console.WriteLine(p.FirstName);
//public constructor
p = FastNew.CreateInstance<Person,string>("test");
Console.WriteLine(p.FirstName);




namespace FastGenericNewDemo;

class Person
{
    private Person()
    {
        FirstName = "Andrei";
    }
    public Person(string firstName)
    {
        this.FirstName=firstName;
    }
    public string FirstName { get; set; }
}


 

The code that is generated is

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by FastGenericNew.SourceGenerator
//     Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#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
{
public static partial class FastNew{

        /// <summary>
        /// <para>Create an instance of <typeparamref name="T" /></para>
        /// <para>Returns <c><see langword="new" /> <typeparamref name="T" />()</c> if <typeparamref name="T"/> is a <see cref="ValueType"/>(struct)</para>
        /// <para>This <b>CAN</b> call the Parameterless Constructor of the <see cref="ValueType"/>(struct)</para>
        /// </summary>
        /// <typeparam name="T">The type to create.</typeparam>
        /// <returns>A new instance of <typeparamref name="T" /></returns>
        /// <remarks>
        /// Equivalent to <c><see langword="new" /> <typeparamref name="T" />()</c> for both Reference Types and Value Types
        /// </remarks>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
	    public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T>()
	    {
#if NETFRAMEWORK
            return global::@FastGenericNew.FastNew<T>.CompiledDelegate();
#else
		    return typeof(T).IsValueType
                ? System.Activator.CreateInstance<T>() // This will be optimized by JIT
                : global::@FastGenericNew.FastNew<T>.CompiledDelegate();
#endif
	    }
        /// <summary>
        /// Create an instance of <typeparamref name="T" /> <br/>
        /// Returns <c><see langword="default" />(<typeparamref name="T" />)</c> if <typeparamref name="T"/> is a <see cref="ValueType"/>(struct) <br/>
        /// This <b>WILL NOT</b> call the Parameterless Constructor of the <see cref="ValueType"/>(struct)
        /// </summary>
        /// <typeparam name="T">The type to create.</typeparam>
        /// <returns>A new instance of <typeparamref name="T" /></returns>
        /// <remarks>
        /// For reference types, equivalent to <c><see langword="new" /> <typeparamref name="T" />()</c> <br/>
        /// For value types, equivalent to <c><see langword="default" />(<typeparamref name="T" />)</c>
        /// </remarks>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
	    public static T NewOrDefault<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T>()
	    {
#if NETFRAMEWORK
		    return global::@FastGenericNew.FastNew<T>._isValueTypeT
#else
		    return typeof(T).IsValueType
#endif
                ? default(T)! // This will never be null since T is a ValueType
                : FastNew<T>.CompiledDelegate();
	    }
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0>(TArg0 p0) =>
global::@FastGenericNew.FastNew<T, TArg0>.CompiledDelegate(p0);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1>(TArg0 p0, TArg1 p1) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1>.CompiledDelegate(p0, p1);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2>(TArg0 p0, TArg1 p1, TArg2 p2) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2>.CompiledDelegate(p0, p1, p2);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3>.CompiledDelegate(p0, p1, p2, p3);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4>.CompiledDelegate(p0, p1, p2, p3, p4);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5>.CompiledDelegate(p0, p1, p2, p3, p4, p5);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12, TArg13 p13) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12, TArg13 p13, TArg14 p14) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14);
public static T CreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12, TArg13 p13, TArg14 p14, TArg15 p15) =>
global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15);
}
}

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by FastGenericNew.SourceGenerator
//     Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#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
{
public static partial class FastNew{

	    [MethodImpl(MethodImplOptions.AggressiveInlining)]
	    public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T>(out T result)
	    {
            if(global::@FastGenericNew.FastNew<T>.IsValid)
            {
#if NETFRAMEWORK
                result = global::@FastGenericNew.FastNew<T>.CompiledDelegate();
#else
		        result = typeof(T).IsValueType
                    ? System.Activator.CreateInstance<T>()
                    : global::@FastGenericNew.FastNew<T>.CompiledDelegate();
#endif
                return true;
            }
	        //Unsafe.SkipInit<T>(out result);
            result = default!;
	        return false;
	    }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
	    public static bool TryNewOrDefault<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T>(out T result)
	    {
            if(global::@FastGenericNew.FastNew<T>.IsValid)
            {
#if NETFRAMEWORK
		        result = global::@FastGenericNew.FastNew<T>._isValueTypeT
#else
    		    result = typeof(T).IsValueType
#endif
                    ? default(T)! // This will never be null since T is a ValueType
                    : FastNew<T>.CompiledDelegate();
                    return true;
            }
	        //Unsafe.SkipInit<T>(out result);
            result = default!;
	        return false;
	    }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0>(TArg0 p0, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0>.CompiledDelegate(p0);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1>(TArg0 p0, TArg1 p1, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1>.CompiledDelegate(p0, p1);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2>(TArg0 p0, TArg1 p1, TArg2 p2, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2>.CompiledDelegate(p0, p1, p2);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3>.CompiledDelegate(p0, p1, p2, p3);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4>.CompiledDelegate(p0, p1, p2, p3, p4);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5>.CompiledDelegate(p0, p1, p2, p3, p4, p5);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12, TArg13 p13, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12, TArg13 p13, TArg14 p14, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14);
return true;
}
result = default!;return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15>(TArg0 p0, TArg1 p1, TArg2 p2, TArg3 p3, TArg4 p4, TArg5 p5, TArg6 p6, TArg7 p7, TArg8 p8, TArg9 p9, TArg10 p10, TArg11 p11, TArg12 p12, TArg13 p13, TArg14 p14, TArg15 p15, out T result)
{
if (global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15>.IsValid)
{
result = global::@FastGenericNew.FastNew<T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15>.CompiledDelegate(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15);
return true;
}
result = default!;return false;
}
}
}

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by FastGenericNew.SourceGenerator
//     Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#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
{
internal 
#if NETFRAMEWORK
static partial class FastNew<
#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
		/// <summary>
		/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
		/// Could be <see langword="null" /> if the constructor couldn't be found.
		/// </summary>
		public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);

	    public static readonly Func<T> CompiledDelegate = System.Linq.Expressions.Expression.Lambda<Func<T>>(typeof(T).IsValueType
            ? (global::@FastGenericNew.FastNew<T>.CachedConstructor != null
                ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(global::@FastGenericNew.FastNew<T>.CachedConstructor)
                : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(typeof(T)))
            : ((global::@FastGenericNew.FastNew<T>.CachedConstructor != null && !typeof(T).IsAbstract)
                ? (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.New(global::@FastGenericNew.FastNew<T>.CachedConstructor)
                : (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Call(global::@FastGenericNew.ThrowHelper.GetSmartThrow<T>()))
            , Array.Empty<System.Linq.Expressions.ParameterExpression>()).Compile();
    
        public static readonly bool IsValid = typeof(T).IsValueType || (global::@FastGenericNew.FastNew<T>.CachedConstructor != null && !typeof(T).IsAbstract);
    }
#else
static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T>
    {
		/// <summary>
		/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
		/// Could be <see langword="null" /> if the constructor couldn't be found.
		/// </summary>
		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<T> CompiledDelegate;
    
        public static readonly bool IsValid = typeof(T).IsValueType || (global::@FastGenericNew.FastNew<T>.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<T>.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<T>());
            }
            il.Emit(OpCodes.Ret);
            CompiledDelegate = (Func<T>)dm.CreateDelegate(typeof(Func<T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
        }
    }
#endif
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[]
{
typeof(TArg0),
}, null);
public static readonly Func<TArg0, T> CompiledDelegate;
public static readonly bool IsValid;
static FastNew()
{
IsValid = CachedConstructor != null && !typeof(T).IsAbstract;
#if NETFRAMEWORK
var p0 = System.Linq.Expressions.Expression.Parameter(typeof(TArg0));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, T>)dm.CreateDelegate(typeof(Func<TArg0, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[]
{
typeof(TArg0),
typeof(TArg1),
}, null);
public static readonly Func<TArg0, TArg1, T> CompiledDelegate;
public static readonly bool IsValid;
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[]
{
typeof(TArg0),
typeof(TArg1),
typeof(TArg2),
}, null);
public static readonly Func<TArg0, TArg1, TArg2, T> CompiledDelegate;
public static readonly bool IsValid;
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[]
{
typeof(TArg0),
typeof(TArg1),
typeof(TArg2),
typeof(TArg3),
}, null);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, T> CompiledDelegate;
public static readonly bool IsValid;
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[]
{
typeof(TArg0),
typeof(TArg1),
typeof(TArg2),
typeof(TArg3),
typeof(TArg4),
}, null);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, T> CompiledDelegate;
public static readonly bool IsValid;
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, T> CompiledDelegate;
public static readonly bool IsValid;
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, T> CompiledDelegate;
public static readonly bool IsValid;
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));
var p6 = System.Linq.Expressions.Expression.Parameter(typeof(TArg6));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, T> CompiledDelegate;
public static readonly bool IsValid;
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));
var p6 = System.Linq.Expressions.Expression.Parameter(typeof(TArg6));
var p7 = System.Linq.Expressions.Expression.Parameter(typeof(TArg7));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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));
var p9 = System.Linq.Expressions.Expression.Parameter(typeof(TArg9));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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));
var p9 = System.Linq.Expressions.Expression.Parameter(typeof(TArg9));
var p10 = System.Linq.Expressions.Expression.Parameter(typeof(TArg10));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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));
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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));
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));
var p12 = System.Linq.Expressions.Expression.Parameter(typeof(TArg12));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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));
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));
var p12 = System.Linq.Expressions.Expression.Parameter(typeof(TArg12));
var p13 = System.Linq.Expressions.Expression.Parameter(typeof(TArg13));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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));
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));
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 = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
internal static partial class FastNew<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15>
{
/// <summary>
/// The constructor of <typeparamref name="T" /> with given arguments. <br/>
/// Could be <see langword="null" /> if the constructor couldn't be found.
/// </summary>
public static readonly ConstructorInfo? CachedConstructor = 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);
public static readonly Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15, T> CompiledDelegate;
public static readonly bool IsValid;
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));
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));
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));
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));
var p15 = System.Linq.Expressions.Expression.Parameter(typeof(TArg15));
CompiledDelegate = (System.Linq.Expressions.Expression.Lambda<Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15, T>>(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<T>())
, 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<T>());
}
il.Emit(OpCodes.Ret);
CompiledDelegate = (Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15, T>)dm.CreateDelegate(typeof(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15, T>), global::@FastGenericNew._FastNewDynMetClosure.Instance);
#endif
}
}
}

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by FastGenericNew.SourceGenerator
//     Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#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 static partial class ThrowHelper
    {
        [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]

#if NET5_0_OR_GREATER
        [DynamicDependency("SmartThrowImpl``1()", typeof(global::@FastGenericNew.ThrowHelper))]
#endif

        public static System.Reflection.MethodInfo GetSmartThrow<T>() => 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<T>()
        {
            var qualifiedName = typeof(T).AssemblyQualifiedName;

            if (typeof(T).IsInterface)
                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: '{ qualifiedName }'");

            throw new System.MissingMethodException($"No match constructor found in type: '{ qualifiedName }'");
        }
    }
}

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by FastGenericNew.SourceGenerator
//     Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#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
{
public static partial class FastNew{
public static Func<T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T>(Type type) =>
(Func<T>)typeof(FastNew<>).MakeGenericType(type).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0>(Type type, Type p0) =>
(Func<TArg0, T>)typeof(FastNew<,>).MakeGenericType(type, p0).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1>(Type type, Type p0, Type p1) =>
(Func<TArg0, TArg1, T>)typeof(FastNew<,,>).MakeGenericType(type, p0, p1).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2>(Type type, Type p0, Type p1, Type p2) =>
(Func<TArg0, TArg1, TArg2, T>)typeof(FastNew<,,,>).MakeGenericType(type, p0, p1, p2).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3>(Type type, Type p0, Type p1, Type p2, Type p3) =>
(Func<TArg0, TArg1, TArg2, TArg3, T>)typeof(FastNew<,,,,>).MakeGenericType(type, p0, p1, p2, p3).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, T>)typeof(FastNew<,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, T>)typeof(FastNew<,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, T>)typeof(FastNew<,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, T>)typeof(FastNew<,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, T>)typeof(FastNew<,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8, Type p9) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, T>)typeof(FastNew<,,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8, Type p9, Type p10) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, T>)typeof(FastNew<,,,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8, Type p9, Type p10, Type p11) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, T>)typeof(FastNew<,,,,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8, Type p9, Type p10, Type p11, Type p12) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, T>)typeof(FastNew<,,,,,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8, Type p9, Type p10, Type p11, Type p12, Type p13) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, T>)typeof(FastNew<,,,,,,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8, Type p9, Type p10, Type p11, Type p12, Type p13, Type p14) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, T>)typeof(FastNew<,,,,,,,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14).GetField("CompiledDelegate")!.GetValue(null)!;public static Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15, T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
#endif
T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15>(Type type, Type p0, Type p1, Type p2, Type p3, Type p4, Type p5, Type p6, Type p7, Type p8, Type p9, Type p10, Type p11, Type p12, Type p13, Type p14, Type p15) =>
(Func<TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TArg11, TArg12, TArg13, TArg14, TArg15, T>)typeof(FastNew<,,,,,,,,,,,,,,,,>).MakeGenericType(type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15).GetField("CompiledDelegate")!.GetValue(null)!;}
}

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by FastGenericNew.SourceGenerator
//     Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#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();
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/FastGenericNew

RSCG – Breezy

RSCG – Breezy
 
 

name Breezy
nuget https://www.nuget.org/packages/Breezy.SourceGenerator/
link https://github.com/Ludovicdln/Breezy
author Ludovicdln

ORM Mapper

 

This is how you can use Breezy .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
	<ItemGroup>
	  <PackageReference Include="Breezy.SourceGenerator" Version="1.0.1"  OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
	  <PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
	</ItemGroup>
</Project>


The code that you will use is



using var connection = new SqlConnection();
//in the order of the properties in Person.cs
var persons = await connection.QueryAsync<Person>("SELECT Id,firstname, lastname FROM person");



namespace BreezyDemo;

[Table("person")]//this is Breezy.Table
public class Person
{
    public int ID { get; set; }
    public string? FirstName { get; set; }
    public string? LastName { get; set; }
}



global using Breezy;
global using Microsoft.Data.SqlClient;
global using BreezyDemo;


 

The code that is generated is

// <auto-generated /> 
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace DbConnectionExtensions
{
    public static class DbConnectionExtensions
    {
        /// <summary>
        /// Execute a command asynchronously using Task.
        /// </summary>       
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <returns>The number of rows affected.</returns>
        public static async Task<int> ExecuteAsync(this DbConnection connection, string sql, CancellationToken cancellationToken = default)
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            await using var command = connection.CreateCommand();
            command.CommandText = sql;
            try
            {
                return await command.ExecuteNonQueryAsync(cancellationToken);
            }
            finally
            {
                if (wasClosed)
                    connection.Close();
            }
        }

        /// <summary>
        /// Execute a command asynchronously using Task.
        /// </summary>       
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "param">The parameters to pass, if any.</param>
        /// <returns>The number of rows affected.</returns>
        public static async Task<int> ExecuteAsync(this DbConnection connection, string sql, object param, CancellationToken cancellationToken = default)
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            await using var command = connection.CreateCommand();
            command.CommandText = sql;
            foreach (var property in param.GetType().GetProperties())
            {
                var parameter = command.CreateParameter();
                parameter.ParameterName = "@" + property.Name;
                parameter.Value = property.GetValue(param);
                command.Parameters.Add(parameter);
            }

            try
            {
                return await command.ExecuteNonQueryAsync(cancellationToken);
            }
            finally
            {
                if (wasClosed)
                    connection.Close();
            }
        }

        /// <summary>
        /// Execute a command asynchronously using Task.
        /// </summary>       
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "transaction">The transaction to use for this query.</param>
        /// <returns>The number of rows affected.</returns>
        public static async Task<int[]> ExecuteAsync(this DbConnection connection, string[] sql, DbTransaction transaction, CancellationToken cancellationToken = default)
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            var commands = new DbCommand[sql.Length];
            for (var i = 0; i < sql.Length; i++)
            {
                await using var command = connection.CreateCommand();
                command.CommandText = sql[i];
                command.Transaction = transaction;
                commands[i] = command;
            }

            try
            {
                var results = new int[sql.Length];
                for (var i = 0; i < commands.Length; i++)
                    results[i] = await commands[i].ExecuteNonQueryAsync(cancellationToken);
                await transaction.CommitAsync();
                return results;
            }
            catch (DbException e)
            {
                await transaction.RollbackAsync();
                return Array.Empty<int>();
            }
            finally
            {
                transaction.Dispose();
                if (wasClosed)
                    connection.Close();
            }
        }

        /// <summary>
        /// Execute a command asynchronously using Task.
        /// </summary>       
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "param">The parameters to pass, if any.</param>
        /// <param name = "transaction">The transaction to use for this query.</param>
        /// <returns>The number of rows affected.</returns>
        public static async Task<int[]> ExecuteAsync(this DbConnection connection, string[] sql, object[] param, DbTransaction transaction, CancellationToken cancellationToken = default)
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            var commands = new DbCommand[sql.Length];
            for (var i = 0; i < sql.Length; i++)
            {
                await using var command = connection.CreateCommand();
                command.CommandText = sql[i];
                command.Transaction = transaction;
                var paramt = param[i];
                foreach (var property in paramt.GetType().GetProperties())
                {
                    var parameter = command.CreateParameter();
                    parameter.ParameterName = "@" + property.Name;
                    parameter.Value = property.GetValue(paramt);
                    command.Parameters.Add(parameter);
                }

                commands[i] = command;
            }

            try
            {
                var results = new int[sql.Length];
                for (var i = 0; i < commands.Length; i++)
                    results[i] = await commands[i].ExecuteNonQueryAsync(cancellationToken);
                await transaction.CommitAsync();
                return results;
            }
            catch (DbException e)
            {
                await transaction.RollbackAsync();
                return Array.Empty<int>();
            }
            finally
            {
                transaction.Dispose();
                if (wasClosed)
                    connection.Close();
            }
        }
    }
}
// <auto-generated />
using System;

namespace Breezy;

public interface ICacheableQuery<T> where T : class
{
	public Task<IEnumerable<T>> GetCacheableResultsAsync(IdentityQuery identityQuery);
	public Task SetCacheableResultsAsync(IdentityQuery identityQuery, IEnumerable<T> results);
}	
		// <auto-generated />
		using System;

		namespace Breezy;

		public class IdentityQuery : IEquatable<IdentityQuery>        
        {
            private readonly int _hashCodeSql;
            private readonly int? _hashCodeParam;
            public IdentityQuery(string sql, object? param = null) => (_hashCodeSql, _hashCodeParam) = (sql.GetHashCode(), param?.GetHashCode());
            public bool Equals(IdentityQuery? other)
            {
                if (ReferenceEquals(other, this)) return true;
                return this.GetHashCode() == other?.GetHashCode();
            }
            public override string ToString() 
                => $"{_hashCodeSql.ToString()}-{_hashCodeParam?.ToString()}";
            public override bool Equals(object? obj)      
                => Equals(obj as IdentityQuery);          
            public override int GetHashCode()         
                => HashCode.Combine(_hashCodeSql, _hashCodeParam);    
        }   
// <auto-generated /> 
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace BreezyDemo
{
    public static class PersonExtensions
    {
        /// <summary>
        /// Execute a query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of results to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<IEnumerable<Person>> QueryAsync<T>(this DbConnection connection, string sql, CancellationToken cancellationToken = default)
            where T : Person
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            await using var command = connection.CreateCommand();
            command.CommandText = sql;
            await using var reader = await command.ExecuteReaderAsync(cancellationToken: cancellationToken);
            var persons = new Dictionary<int, Person>();
            try
            {
                while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                {
                    Person person = null;
                    var person1Id = reader.IsDBNull(0) ? default : reader.GetInt32(0);
                    if (!persons.TryGetValue(person1Id, out person))
                    {
                        person = new Person()
                        {
                            ID = person1Id,
                            FirstName = reader.IsDBNull(1) ? default : reader.GetString(1),
                            LastName = reader.IsDBNull(2) ? default : reader.GetString(2),
                        };
                        persons.Add(person1Id, person);
                    }
                }

                return persons.Values;
            }
            finally
            {
                reader.Close();
                if (wasClosed)
                    connection.Close();
            }
        }

        /// <summary>
        /// Execute a query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of results to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "param">The parameters to pass, if any.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<IEnumerable<Person>> QueryAsync<T>(this DbConnection connection, string sql, object param, CancellationToken cancellationToken = default)
            where T : Person
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            await using var command = connection.CreateCommand();
            command.CommandText = sql;
            foreach (var property in param.GetType().GetProperties())
            {
                var parameter = command.CreateParameter();
                parameter.ParameterName = "@" + property.Name;
                parameter.Value = property.GetValue(param);
                command.Parameters.Add(parameter);
            }

            await using var reader = await command.ExecuteReaderAsync(cancellationToken: cancellationToken);
            var persons = new Dictionary<int, Person>();
            try
            {
                while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                {
                    Person person = null;
                    var person1Id = reader.IsDBNull(0) ? default : reader.GetInt32(0);
                    if (!persons.TryGetValue(person1Id, out person))
                    {
                        person = new Person()
                        {
                            ID = person1Id,
                            FirstName = reader.IsDBNull(1) ? default : reader.GetString(1),
                            LastName = reader.IsDBNull(2) ? default : reader.GetString(2),
                        };
                        persons.Add(person1Id, person);
                    }
                }

                return persons.Values;
            }
            finally
            {
                reader.Close();
                if (wasClosed)
                    connection.Close();
            }
        }

        /// <summary>
        /// Execute a query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of results to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "cacheableQuery">The cache that you need to impl, if you want to be faster.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<IEnumerable<Person>> QueryAsync<T>(this DbConnection connection, string sql, ICacheableQuery<Person> cacheableQuery, CancellationToken cancellationToken = default)
            where T : Person
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            await using var command = connection.CreateCommand();
            command.CommandText = sql;
            var identityQuery = new IdentityQuery(sql);
            var cacheableResults = await cacheableQuery.GetCacheableResultsAsync(identityQuery);
            if (cacheableResults.Any())
                return cacheableResults;
            await using var reader = await command.ExecuteReaderAsync(cancellationToken: cancellationToken);
            var persons = new Dictionary<int, Person>();
            try
            {
                while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                {
                    Person person = null;
                    var person1Id = reader.IsDBNull(0) ? default : reader.GetInt32(0);
                    if (!persons.TryGetValue(person1Id, out person))
                    {
                        person = new Person()
                        {
                            ID = person1Id,
                            FirstName = reader.IsDBNull(1) ? default : reader.GetString(1),
                            LastName = reader.IsDBNull(2) ? default : reader.GetString(2),
                        };
                        persons.Add(person1Id, person);
                    }
                }

                await cacheableQuery.SetCacheableResultsAsync(identityQuery, persons.Values);
                return persons.Values;
            }
            finally
            {
                reader.Close();
                if (wasClosed)
                    connection.Close();
            }
        }

        /// <summary>
        /// Execute a query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of results to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "param">The parameters to pass, if any.</param>
        /// <param name = "cacheableQuery">The cache that you need to impl, if you want to be faster.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<IEnumerable<Person>> QueryAsync<T>(this DbConnection connection, string sql, object param, ICacheableQuery<Person> cacheableQuery, CancellationToken cancellationToken = default)
            where T : Person
        {
            bool wasClosed = connection.State == ConnectionState.Closed;
            if (wasClosed)
                await connection.OpenAsync(cancellationToken);
            await using var command = connection.CreateCommand();
            command.CommandText = sql;
            foreach (var property in param.GetType().GetProperties())
            {
                var parameter = command.CreateParameter();
                parameter.ParameterName = "@" + property.Name;
                parameter.Value = property.GetValue(param);
                command.Parameters.Add(parameter);
            }

            var identityQuery = new IdentityQuery(sql);
            var cacheableResults = await cacheableQuery.GetCacheableResultsAsync(identityQuery);
            if (cacheableResults.Any())
                return cacheableResults;
            await using var reader = await command.ExecuteReaderAsync(cancellationToken: cancellationToken);
            var persons = new Dictionary<int, Person>();
            try
            {
                while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                {
                    Person person = null;
                    var person1Id = reader.IsDBNull(0) ? default : reader.GetInt32(0);
                    if (!persons.TryGetValue(person1Id, out person))
                    {
                        person = new Person()
                        {
                            ID = person1Id,
                            FirstName = reader.IsDBNull(1) ? default : reader.GetString(1),
                            LastName = reader.IsDBNull(2) ? default : reader.GetString(2),
                        };
                        persons.Add(person1Id, person);
                    }
                }

                await cacheableQuery.SetCacheableResultsAsync(identityQuery, persons.Values);
                return persons.Values;
            }
            finally
            {
                reader.Close();
                if (wasClosed)
                    connection.Close();
            }
        }

        /// <summary>
        /// Execute a single-row query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of result to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A first sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<Person?> QueryFirstOrDefaultAsync<T>(this DbConnection connection, string sql, CancellationToken cancellationToken = default)
            where T : Person
        {
            return (await connection.QueryAsync<Person>(sql, cancellationToken)).FirstOrDefault();
        }

        /// <summary>
        /// Execute a single-row query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of result to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "param">The parameters to pass, if any.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A first sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<Person?> QueryFirstOrDefaultAsync<T>(this DbConnection connection, string sql, object param, CancellationToken cancellationToken = default)
            where T : Person
        {
            return (await connection.QueryAsync<Person>(sql, param, cancellationToken)).FirstOrDefault();
        }

        /// <summary>
        /// Execute a single-row query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of result to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "cacheableQuery">The cache that you need to impl, if you want to be faster.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A first sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<Person?> QueryFirstOrDefaultAsync<T>(this DbConnection connection, string sql, ICacheableQuery<Person> cacheableQuery, CancellationToken cancellationToken = default)
            where T : Person
        {
            return (await connection.QueryAsync<Person>(sql, cacheableQuery, cancellationToken)).FirstOrDefault();
        }

        /// <summary>
        /// Execute a single-row query asynchronously using Task.
        /// </summary>
        /// <typeparam name = "T">The type of result to return.</typeparam>
        /// <param name = "sql">The SQL to execute for the query.</param>
        /// <param name = "param">The parameters to pass, if any.</param>
        /// <param name = "cacheableQuery">The cache that you need to impl, if you want to be faster.</param>
        /// <param name = "cancellationToken">The cancellation token for this command.</param>
        /// <returns>
        /// A first sequence of data of <typeparamref name = "T"/>;
        /// </returns>
        public static async Task<Person?> QueryFirstOrDefaultAsync<T>(this DbConnection connection, string sql, object param, ICacheableQuery<Person> cacheableQuery, CancellationToken cancellationToken = default)
            where T : Person
        {
            return (await connection.QueryAsync<Person>(sql, param, cacheableQuery, cancellationToken)).FirstOrDefault();
        }
    }
}
// <auto-generated />
using System;

namespace Breezy;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class SplitOnAttribute : Attribute
{
	public int[] Index { get; init; }

	public SplitOnAttribute(params int[] index) => Index = index ?? throw new ArgumentNullException("index not defined"); 
}
// <auto-generated />
using System;

namespace Breezy;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class TableAttribute : Attribute
{
	public string Name { get; init; }

	public TableAttribute(string name) => Name = name ?? throw new ArgumentNullException(name); 
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Breezy

RSCG – EnumClass

RSCG – EnumClass
 
 

name EnumClass
nuget https://www.nuget.org/packages/EnumClass.Generator/
link https://github.com/ashenBlade/EnumClass
author ashen.Blade

enum 2 class

 

This is how you can use EnumClass .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EnumClass.Generator" Version="1.3.0" OutputItemType="Analyzer" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

Console.WriteLine(EnumClassDemo.EnumClass.Colors.None.ToString());
Console.WriteLine(EnumClassDemo.EnumClass.Colors.Red.TestMe());



using EnumClass.Attributes;

namespace EnumClassDemo;
[EnumClass]
public enum Colors
{
    None=0,
    Red,
    Green,
    Blue,
}



namespace EnumClassDemo.EnumClass;
public abstract partial class Colors
{
    public partial class RedEnumValue
    {
        public string? TestMe()
        {
            return ToString();
        }
    }
}

 

The code that is generated is

#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace EnumClassDemo.EnumClass
{

public abstract partial class Colors: IEquatable<Colors>, IEquatable<global::EnumClassDemo.Colors>, IComparable<Colors>, IComparable<global::EnumClassDemo.Colors>, IComparable
{
    protected readonly global::EnumClassDemo.Colors _realEnumValue;

    protected Colors(global::EnumClassDemo.Colors enumValue)
    {
        this._realEnumValue = enumValue;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static explicit operator global::EnumClassDemo.Colors(Colors value)
    {
        return value._realEnumValue;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator int(Colors value)
    {
        return (int) value._realEnumValue;
    }

    public bool Equals(Colors? other)
    {
        return !ReferenceEquals(other, null) && other._realEnumValue == this._realEnumValue;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public bool Equals(global::EnumClassDemo.Colors other)
    {
        return other == this._realEnumValue;
    }

    public override bool Equals(object? other)
    {
        if (ReferenceEquals(other, null)) return false;
        if (ReferenceEquals(other, this)) return true;
        if (other is Colors)
        {
            return this.Equals((Colors) other);
        }
        if (other is global::EnumClassDemo.Colors)
        {
            return this.Equals((global::EnumClassDemo.Colors) other);
        }
        return false;
    }

    public static bool operator ==(Colors left, global::EnumClassDemo.Colors right)
    {
        return left.Equals(right);
    }

    public static bool operator !=(Colors left, global::EnumClassDemo.Colors right)
    {
        return !left.Equals(right);
    }

    public static bool operator ==(global::EnumClassDemo.Colors left, Colors right)
    {
        return right.Equals(left);
    }

    public static bool operator !=(global::EnumClassDemo.Colors left, Colors right)
    {
        return !right.Equals(left);
    }

    public static bool operator ==(Colors left, Colors right)
    {
        return !ReferenceEquals(left, null) && left.Equals(right);
    }

    public static bool operator !=(Colors left, Colors right)
    {
        return ReferenceEquals(left, null) || !left.Equals(right);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public override int GetHashCode()
    {
        return this._realEnumValue.GetHashCode();
    }

    public static bool TryParse(string value, out Colors? colors)
    {
        switch (value)
        {
            case "None":
                colors = None;
                return true;
            case "Red":
                colors = Red;
                return true;
            case "Green":
                colors = Green;
                return true;
            case "Blue":
                colors = Blue;
                return true;
            case "Colors.None":
                colors = None;
                return true;
            case "Colors.Red":
                colors = Red;
                return true;
            case "Colors.Green":
                colors = Green;
                return true;
            case "Colors.Blue":
                colors = Blue;
                return true;
        }
        colors = null;
        return false;
    }


    public static bool TryParse(int value, out Colors? colors)
    {
        switch (value)
        {
            case 0:
                colors = None;
                return true;
            case 1:
                colors = Red;
                return true;
            case 2:
                colors = Green;
                return true;
            case 3:
                colors = Blue;
                return true;
        }
        colors = null;
        return false;
    }


    public int CompareTo(object? other)
    {
        if (ReferenceEquals(this, other)) return 0;
        if (ReferenceEquals(null, other)) return 1;
        if (other is Colors)
        {
            Colors temp = (Colors) other;
            int left = ((int)this._realEnumValue);
            int right = ((int)temp._realEnumValue);
            return left < right ? -1 : left == right ? 0 : 1;
        }
        if (other is global::EnumClassDemo.Colors)
        {
            int left = ((int)this._realEnumValue);
            int right = ((int)other);
            return left < right ? -1 : left == right ? 0 : 1;
        }
        throw new ArgumentException($"Object to compare must be either {typeof(Colors)} or {typeof(global::EnumClassDemo.Colors)}. Given type: {other.GetType()}", "other");
    }

    public int CompareTo(Colors? other)
    {
        if (ReferenceEquals(this, other)) return 0;
        if (ReferenceEquals(null, other)) return 1;
            int left = ((int)this._realEnumValue);
            int right = ((int)other._realEnumValue);
            return left < right ? -1 : left == right ? 0 : 1;
    }

    public int CompareTo(global::EnumClassDemo.Colors other)
    {
            int left = ((int)this._realEnumValue);
            int right = ((int)other);
            return left < right ? -1 : left == right ? 0 : 1;
    }

    public abstract void Switch(Action<NoneEnumValue> noneSwitch, Action<RedEnumValue> redSwitch, Action<GreenEnumValue> greenSwitch, Action<BlueEnumValue> blueSwitch);
    public abstract TResult Switch<TResult>(Func<NoneEnumValue, TResult> noneSwitch, Func<RedEnumValue, TResult> redSwitch, Func<GreenEnumValue, TResult> greenSwitch, Func<BlueEnumValue, TResult> blueSwitch);
    public abstract void Switch<T0>(T0 arg0, Action<NoneEnumValue, T0> noneSwitch, Action<RedEnumValue, T0> redSwitch, Action<GreenEnumValue, T0> greenSwitch, Action<BlueEnumValue, T0> blueSwitch);
    public abstract TResult Switch<TResult, T0>(T0 arg0, Func<NoneEnumValue, T0, TResult> noneSwitch, Func<RedEnumValue, T0, TResult> redSwitch, Func<GreenEnumValue, T0, TResult> greenSwitch, Func<BlueEnumValue, T0, TResult> blueSwitch);
    public abstract void Switch<T0, T1>(T0 arg0, T1 arg1, Action<NoneEnumValue, T0, T1> noneSwitch, Action<RedEnumValue, T0, T1> redSwitch, Action<GreenEnumValue, T0, T1> greenSwitch, Action<BlueEnumValue, T0, T1> blueSwitch);
    public abstract TResult Switch<TResult, T0, T1>(T0 arg0, T1 arg1, Func<NoneEnumValue, T0, T1, TResult> noneSwitch, Func<RedEnumValue, T0, T1, TResult> redSwitch, Func<GreenEnumValue, T0, T1, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, TResult> blueSwitch);
    public abstract void Switch<T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Action<NoneEnumValue, T0, T1, T2> noneSwitch, Action<RedEnumValue, T0, T1, T2> redSwitch, Action<GreenEnumValue, T0, T1, T2> greenSwitch, Action<BlueEnumValue, T0, T1, T2> blueSwitch);
    public abstract TResult Switch<TResult, T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Func<NoneEnumValue, T0, T1, T2, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, TResult> blueSwitch);
    public abstract void Switch<T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Action<NoneEnumValue, T0, T1, T2, T3> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3> blueSwitch);
    public abstract TResult Switch<TResult, T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Func<NoneEnumValue, T0, T1, T2, T3, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, TResult> blueSwitch);
    public abstract void Switch<T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<NoneEnumValue, T0, T1, T2, T3, T4> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4> blueSwitch);
    public abstract TResult Switch<TResult, T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func<NoneEnumValue, T0, T1, T2, T3, T4, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, TResult> blueSwitch);
    public abstract void Switch<T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5> blueSwitch);
    public abstract TResult Switch<TResult, T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, TResult> blueSwitch);
    public abstract void Switch<T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5, T6> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6> blueSwitch);
    public abstract TResult Switch<TResult, T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> blueSwitch);

    public static readonly NoneEnumValue None = new NoneEnumValue();
    public partial class NoneEnumValue: Colors
    {
        public NoneEnumValue(): base(global::EnumClassDemo.Colors.None) { }
        public override string ToString()
        {
            return "None";
        }

        public override void Switch(Action<NoneEnumValue> noneSwitch, Action<RedEnumValue> redSwitch, Action<GreenEnumValue> greenSwitch, Action<BlueEnumValue> blueSwitch)
        {
            noneSwitch(this);
        }

        public override TResult Switch<TResult>(Func<NoneEnumValue, TResult> noneSwitch, Func<RedEnumValue, TResult> redSwitch, Func<GreenEnumValue, TResult> greenSwitch, Func<BlueEnumValue, TResult> blueSwitch)
        {
            return noneSwitch(this);
        }

        public override void Switch<T0>(T0 arg0, Action<NoneEnumValue, T0> noneSwitch, Action<RedEnumValue, T0> redSwitch, Action<GreenEnumValue, T0> greenSwitch, Action<BlueEnumValue, T0> blueSwitch)
        {
            noneSwitch(this, arg0);
        }

        public override TResult Switch<TResult, T0>(T0 arg0, Func<NoneEnumValue, T0, TResult> noneSwitch, Func<RedEnumValue, T0, TResult> redSwitch, Func<GreenEnumValue, T0, TResult> greenSwitch, Func<BlueEnumValue, T0, TResult> blueSwitch)
        {
            return noneSwitch(this, arg0);
        }

        public override void Switch<T0, T1>(T0 arg0, T1 arg1, Action<NoneEnumValue, T0, T1> noneSwitch, Action<RedEnumValue, T0, T1> redSwitch, Action<GreenEnumValue, T0, T1> greenSwitch, Action<BlueEnumValue, T0, T1> blueSwitch)
        {
            noneSwitch(this, arg0, arg1);
        }

        public override TResult Switch<TResult, T0, T1>(T0 arg0, T1 arg1, Func<NoneEnumValue, T0, T1, TResult> noneSwitch, Func<RedEnumValue, T0, T1, TResult> redSwitch, Func<GreenEnumValue, T0, T1, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, TResult> blueSwitch)
        {
            return noneSwitch(this, arg0, arg1);
        }

        public override void Switch<T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Action<NoneEnumValue, T0, T1, T2> noneSwitch, Action<RedEnumValue, T0, T1, T2> redSwitch, Action<GreenEnumValue, T0, T1, T2> greenSwitch, Action<BlueEnumValue, T0, T1, T2> blueSwitch)
        {
            noneSwitch(this, arg0, arg1, arg2);
        }

        public override TResult Switch<TResult, T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Func<NoneEnumValue, T0, T1, T2, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, TResult> blueSwitch)
        {
            return noneSwitch(this, arg0, arg1, arg2);
        }

        public override void Switch<T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Action<NoneEnumValue, T0, T1, T2, T3> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3> blueSwitch)
        {
            noneSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Func<NoneEnumValue, T0, T1, T2, T3, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, TResult> blueSwitch)
        {
            return noneSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override void Switch<T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<NoneEnumValue, T0, T1, T2, T3, T4> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4> blueSwitch)
        {
            noneSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func<NoneEnumValue, T0, T1, T2, T3, T4, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, TResult> blueSwitch)
        {
            return noneSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5> blueSwitch)
        {
            noneSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, TResult> blueSwitch)
        {
            return noneSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5, T6> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6> blueSwitch)
        {
            noneSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> blueSwitch)
        {
            return noneSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override int GetHashCode()
        {
            return 0;
        }
    }

    public static readonly RedEnumValue Red = new RedEnumValue();
    public partial class RedEnumValue: Colors
    {
        public RedEnumValue(): base(global::EnumClassDemo.Colors.Red) { }
        public override string ToString()
        {
            return "Red";
        }

        public override void Switch(Action<NoneEnumValue> noneSwitch, Action<RedEnumValue> redSwitch, Action<GreenEnumValue> greenSwitch, Action<BlueEnumValue> blueSwitch)
        {
            redSwitch(this);
        }

        public override TResult Switch<TResult>(Func<NoneEnumValue, TResult> noneSwitch, Func<RedEnumValue, TResult> redSwitch, Func<GreenEnumValue, TResult> greenSwitch, Func<BlueEnumValue, TResult> blueSwitch)
        {
            return redSwitch(this);
        }

        public override void Switch<T0>(T0 arg0, Action<NoneEnumValue, T0> noneSwitch, Action<RedEnumValue, T0> redSwitch, Action<GreenEnumValue, T0> greenSwitch, Action<BlueEnumValue, T0> blueSwitch)
        {
            redSwitch(this, arg0);
        }

        public override TResult Switch<TResult, T0>(T0 arg0, Func<NoneEnumValue, T0, TResult> noneSwitch, Func<RedEnumValue, T0, TResult> redSwitch, Func<GreenEnumValue, T0, TResult> greenSwitch, Func<BlueEnumValue, T0, TResult> blueSwitch)
        {
            return redSwitch(this, arg0);
        }

        public override void Switch<T0, T1>(T0 arg0, T1 arg1, Action<NoneEnumValue, T0, T1> noneSwitch, Action<RedEnumValue, T0, T1> redSwitch, Action<GreenEnumValue, T0, T1> greenSwitch, Action<BlueEnumValue, T0, T1> blueSwitch)
        {
            redSwitch(this, arg0, arg1);
        }

        public override TResult Switch<TResult, T0, T1>(T0 arg0, T1 arg1, Func<NoneEnumValue, T0, T1, TResult> noneSwitch, Func<RedEnumValue, T0, T1, TResult> redSwitch, Func<GreenEnumValue, T0, T1, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, TResult> blueSwitch)
        {
            return redSwitch(this, arg0, arg1);
        }

        public override void Switch<T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Action<NoneEnumValue, T0, T1, T2> noneSwitch, Action<RedEnumValue, T0, T1, T2> redSwitch, Action<GreenEnumValue, T0, T1, T2> greenSwitch, Action<BlueEnumValue, T0, T1, T2> blueSwitch)
        {
            redSwitch(this, arg0, arg1, arg2);
        }

        public override TResult Switch<TResult, T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Func<NoneEnumValue, T0, T1, T2, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, TResult> blueSwitch)
        {
            return redSwitch(this, arg0, arg1, arg2);
        }

        public override void Switch<T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Action<NoneEnumValue, T0, T1, T2, T3> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3> blueSwitch)
        {
            redSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Func<NoneEnumValue, T0, T1, T2, T3, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, TResult> blueSwitch)
        {
            return redSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override void Switch<T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<NoneEnumValue, T0, T1, T2, T3, T4> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4> blueSwitch)
        {
            redSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func<NoneEnumValue, T0, T1, T2, T3, T4, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, TResult> blueSwitch)
        {
            return redSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5> blueSwitch)
        {
            redSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, TResult> blueSwitch)
        {
            return redSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5, T6> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6> blueSwitch)
        {
            redSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> blueSwitch)
        {
            return redSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override int GetHashCode()
        {
            return 1;
        }
    }

    public static readonly GreenEnumValue Green = new GreenEnumValue();
    public partial class GreenEnumValue: Colors
    {
        public GreenEnumValue(): base(global::EnumClassDemo.Colors.Green) { }
        public override string ToString()
        {
            return "Green";
        }

        public override void Switch(Action<NoneEnumValue> noneSwitch, Action<RedEnumValue> redSwitch, Action<GreenEnumValue> greenSwitch, Action<BlueEnumValue> blueSwitch)
        {
            greenSwitch(this);
        }

        public override TResult Switch<TResult>(Func<NoneEnumValue, TResult> noneSwitch, Func<RedEnumValue, TResult> redSwitch, Func<GreenEnumValue, TResult> greenSwitch, Func<BlueEnumValue, TResult> blueSwitch)
        {
            return greenSwitch(this);
        }

        public override void Switch<T0>(T0 arg0, Action<NoneEnumValue, T0> noneSwitch, Action<RedEnumValue, T0> redSwitch, Action<GreenEnumValue, T0> greenSwitch, Action<BlueEnumValue, T0> blueSwitch)
        {
            greenSwitch(this, arg0);
        }

        public override TResult Switch<TResult, T0>(T0 arg0, Func<NoneEnumValue, T0, TResult> noneSwitch, Func<RedEnumValue, T0, TResult> redSwitch, Func<GreenEnumValue, T0, TResult> greenSwitch, Func<BlueEnumValue, T0, TResult> blueSwitch)
        {
            return greenSwitch(this, arg0);
        }

        public override void Switch<T0, T1>(T0 arg0, T1 arg1, Action<NoneEnumValue, T0, T1> noneSwitch, Action<RedEnumValue, T0, T1> redSwitch, Action<GreenEnumValue, T0, T1> greenSwitch, Action<BlueEnumValue, T0, T1> blueSwitch)
        {
            greenSwitch(this, arg0, arg1);
        }

        public override TResult Switch<TResult, T0, T1>(T0 arg0, T1 arg1, Func<NoneEnumValue, T0, T1, TResult> noneSwitch, Func<RedEnumValue, T0, T1, TResult> redSwitch, Func<GreenEnumValue, T0, T1, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, TResult> blueSwitch)
        {
            return greenSwitch(this, arg0, arg1);
        }

        public override void Switch<T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Action<NoneEnumValue, T0, T1, T2> noneSwitch, Action<RedEnumValue, T0, T1, T2> redSwitch, Action<GreenEnumValue, T0, T1, T2> greenSwitch, Action<BlueEnumValue, T0, T1, T2> blueSwitch)
        {
            greenSwitch(this, arg0, arg1, arg2);
        }

        public override TResult Switch<TResult, T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Func<NoneEnumValue, T0, T1, T2, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, TResult> blueSwitch)
        {
            return greenSwitch(this, arg0, arg1, arg2);
        }

        public override void Switch<T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Action<NoneEnumValue, T0, T1, T2, T3> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3> blueSwitch)
        {
            greenSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Func<NoneEnumValue, T0, T1, T2, T3, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, TResult> blueSwitch)
        {
            return greenSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override void Switch<T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<NoneEnumValue, T0, T1, T2, T3, T4> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4> blueSwitch)
        {
            greenSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func<NoneEnumValue, T0, T1, T2, T3, T4, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, TResult> blueSwitch)
        {
            return greenSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5> blueSwitch)
        {
            greenSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, TResult> blueSwitch)
        {
            return greenSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5, T6> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6> blueSwitch)
        {
            greenSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> blueSwitch)
        {
            return greenSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override int GetHashCode()
        {
            return 2;
        }
    }

    public static readonly BlueEnumValue Blue = new BlueEnumValue();
    public partial class BlueEnumValue: Colors
    {
        public BlueEnumValue(): base(global::EnumClassDemo.Colors.Blue) { }
        public override string ToString()
        {
            return "Blue";
        }

        public override void Switch(Action<NoneEnumValue> noneSwitch, Action<RedEnumValue> redSwitch, Action<GreenEnumValue> greenSwitch, Action<BlueEnumValue> blueSwitch)
        {
            blueSwitch(this);
        }

        public override TResult Switch<TResult>(Func<NoneEnumValue, TResult> noneSwitch, Func<RedEnumValue, TResult> redSwitch, Func<GreenEnumValue, TResult> greenSwitch, Func<BlueEnumValue, TResult> blueSwitch)
        {
            return blueSwitch(this);
        }

        public override void Switch<T0>(T0 arg0, Action<NoneEnumValue, T0> noneSwitch, Action<RedEnumValue, T0> redSwitch, Action<GreenEnumValue, T0> greenSwitch, Action<BlueEnumValue, T0> blueSwitch)
        {
            blueSwitch(this, arg0);
        }

        public override TResult Switch<TResult, T0>(T0 arg0, Func<NoneEnumValue, T0, TResult> noneSwitch, Func<RedEnumValue, T0, TResult> redSwitch, Func<GreenEnumValue, T0, TResult> greenSwitch, Func<BlueEnumValue, T0, TResult> blueSwitch)
        {
            return blueSwitch(this, arg0);
        }

        public override void Switch<T0, T1>(T0 arg0, T1 arg1, Action<NoneEnumValue, T0, T1> noneSwitch, Action<RedEnumValue, T0, T1> redSwitch, Action<GreenEnumValue, T0, T1> greenSwitch, Action<BlueEnumValue, T0, T1> blueSwitch)
        {
            blueSwitch(this, arg0, arg1);
        }

        public override TResult Switch<TResult, T0, T1>(T0 arg0, T1 arg1, Func<NoneEnumValue, T0, T1, TResult> noneSwitch, Func<RedEnumValue, T0, T1, TResult> redSwitch, Func<GreenEnumValue, T0, T1, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, TResult> blueSwitch)
        {
            return blueSwitch(this, arg0, arg1);
        }

        public override void Switch<T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Action<NoneEnumValue, T0, T1, T2> noneSwitch, Action<RedEnumValue, T0, T1, T2> redSwitch, Action<GreenEnumValue, T0, T1, T2> greenSwitch, Action<BlueEnumValue, T0, T1, T2> blueSwitch)
        {
            blueSwitch(this, arg0, arg1, arg2);
        }

        public override TResult Switch<TResult, T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2, Func<NoneEnumValue, T0, T1, T2, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, TResult> blueSwitch)
        {
            return blueSwitch(this, arg0, arg1, arg2);
        }

        public override void Switch<T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Action<NoneEnumValue, T0, T1, T2, T3> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3> blueSwitch)
        {
            blueSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, Func<NoneEnumValue, T0, T1, T2, T3, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, TResult> blueSwitch)
        {
            return blueSwitch(this, arg0, arg1, arg2, arg3);
        }

        public override void Switch<T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<NoneEnumValue, T0, T1, T2, T3, T4> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4> blueSwitch)
        {
            blueSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func<NoneEnumValue, T0, T1, T2, T3, T4, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, TResult> blueSwitch)
        {
            return blueSwitch(this, arg0, arg1, arg2, arg3, arg4);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5> blueSwitch)
        {
            blueSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, TResult> blueSwitch)
        {
            return blueSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5);
        }

        public override void Switch<T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6> noneSwitch, Action<RedEnumValue, T0, T1, T2, T3, T4, T5, T6> redSwitch, Action<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6> greenSwitch, Action<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6> blueSwitch)
        {
            blueSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        public override TResult Switch<TResult, T0, T1, T2, T3, T4, T5, T6>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Func<NoneEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> noneSwitch, Func<RedEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> redSwitch, Func<GreenEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> greenSwitch, Func<BlueEnumValue, T0, T1, T2, T3, T4, T5, T6, TResult> blueSwitch)
        {
            return blueSwitch(this, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override int GetHashCode()
        {
            return 3;
        }
    }

    private static readonly Colors[] _members = new Colors[4] { None, Red, Green, Blue, };

    public static System.Collections.Generic.IReadOnlyCollection<Colors> GetAllMembers()
    {
        return _members;
    }
}
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/EnumClass

RSCG – AutoRegisterInject

RSCG – AutoRegisterInject
 
 

name AutoRegisterInject
nuget https://www.nuget.org/packages/AutoRegisterInject/
link https://github.com/patrickklaeren/AutoRegisterInject
author Patrick Klaeren

Generating class DI registration from attributes

 

This is how you can use AutoRegisterInject .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoRegisterInject" Version="1.2.1" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using AutoRegisterInjectDemo;
using Microsoft.Extensions.DependencyInjection;

Console.WriteLine("Hello, World!");
ServiceCollection sc = new();
sc.AutoRegisterFromAutoRegisterInjectDemo();
var b=sc.BuildServiceProvider();
var con = b.GetRequiredService<DatabaseCon>();
var db=b.GetRequiredService<IDatabase>();
db.Open();



namespace AutoRegisterInjectDemo;

[RegisterScoped]
internal class Database : IDatabase
{
    private readonly DatabaseCon con;

    public Database(DatabaseCon con)
    {
        this.con = con;
    }
    public void Open()
    {
        Console.WriteLine($"open {con.Connection}");
    }

}




namespace AutoRegisterInjectDemo
{
    internal interface IDatabase
    {
        void Open();
    }
}


namespace AutoRegisterInjectDemo;

[RegisterSingleton]
internal class DatabaseCon
{
    public string? Connection { get; set; }
}



 

The code that is generated is

// <auto-generated>
//     Automatically generated by AutoRegisterInject.
//     Changes made to this file may be lost and may cause undesirable behaviour.
// </auto-generated>
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class RegisterScopedAttribute : System.Attribute { }
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class RegisterSingletonAttribute : System.Attribute { }
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class RegisterTransientAttribute : System.Attribute { }
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class RegisterHostedServiceAttribute : System.Attribute { }
// <auto-generated>
//     Automatically generated by AutoRegisterInject.
//     Changes made to this file may be lost and may cause undesirable behaviour.
// </auto-generated>
using Microsoft.Extensions.DependencyInjection;
public static class AutoRegisterInjectServiceCollectionExtension
{
    public static Microsoft.Extensions.DependencyInjection.IServiceCollection AutoRegisterFromAutoRegisterInjectDemo(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection)
    {
        return AutoRegister(serviceCollection);
    }

    internal static Microsoft.Extensions.DependencyInjection.IServiceCollection AutoRegister(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection)
    {
        serviceCollection.AddScoped<AutoRegisterInjectDemo.IDatabase, AutoRegisterInjectDemo.Database>();
serviceCollection.AddSingleton<AutoRegisterInjectDemo.DatabaseCon>();
        return serviceCollection;
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/AutoRegisterInject

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.