Skip to main content

AutoGen by Feast Antelcat

Nuget / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Name: AutoGen

Auto generate anything you want

Author: Feast Antelcat

NuGet: https://www.nuget.org/packages/Antelcat.AutoGen/

You can find more details at ,https://github.com/Antelcat/AutoGen

Source : https://github.com/Antelcat/AutoGen

Original Readme​

note

Antelcat.AutoGen

πŸ‡¨πŸ‡³ δΈ­ζ–‡

Auto generate anything you may want

unless we can't

Supported​

Antelcat.AutoGen.ComponentModel :​

  • [AutoStringTo(string, Accessibility)] :​

    Auto generate string To extension

    only on assembly and static partial class

    AutoStringTo

  • Mapping :​

    • [AutoMap(Accessibility)] :​

      Auto generate mappings between types

      Only on partial method

      AutoMapTo

      You can use to generate shallow copy

    • [MapBetween(fromProperty, toProperty)] :​

      Specify property mapping between types

      • By : Method being called when mapping this property
    • [MapIgnore] :​

      To be ignored when generate mapping code

    • [MapInclude(property)] :​

      Explicit include properties when [MapIgnore]

    • [MapExclude(string)] :​

      To be excluded when mapping

    • [MapConstructor(params string[])] :​

      Specified property to be added in constructor, will auto detect if null

  • [AutoFilePath]:​

    Auto generate FilePath which is ref readonly struct

    void Fun([CallerFilePath] string path = "")
    {
    var directory = (FilePath)path << 1;
    var full = directory / "Antelcat.AutoGen.Sample" / "Example.cs";
    var changeExtension = full - 2 + ".g.cs";
    }
  • [AutoDeconstructIndexable]:​

    Auto generate Deconstruct method for IList<> and custom types

    [assembly: AutoDeconstructIndexable(16/*default size is 16*/, typeof(Foo))]

    int[] list = [1,2,3];
    var (a, b, c) = list;

    class Foo{
    public object this[int index] => index;
    }

    var (a, b, c, d) = new Foo();

About​

note

Generating function to map DTOs

How to use​

Example ( source csproj, source files )​

This is the CSharp Project that references AutoGen

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

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

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Antelcat.AutoGen" Version="1.0.0-pre-alpha-7" />
</ItemGroup>


</Project>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/> By Antelcat.AutoGen
#pragma warning disable
#nullable enable
namespace mapperDemo
{
partial class Extensions
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Antelcat.AutoGen.SourceGenerators.Generators.Mapping.MapperGenerator", "1.0.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
public static partial global::mapperDemo.PersonDTO ToDTO(this global::Person person)
{
var ret = new global::mapperDemo.PersonDTO()
{
ID = person.ID,
FirstName = person.FirstName,
LastName = person.LastName,
};
global::mapperDemo.Extensions.AfterMap(person, ret);
return ret;
}
}
}

Usefull​

Download Example (.NET C# )​

Share AutoGen​

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

In the same category (Mapper) - 7 other generators​

AutoDTO​

DynamicsMapper​

LightweightObjectMapper​

MagicMap​

mapperly​

MapTo​

NextGenMapper​