AutoGen by Feast Antelcat
Nuget / site dataβ
Detailsβ
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β
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
andstatic partial class
Mapping
:β[AutoMap(Accessibility)]
:βAuto generate mappings between types
Only on
partial method
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 isref 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 forIList<>
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β
Generating function to map DTOs
How to useβ
Example ( source csproj, source files )β
- CSharp Project
- Program.cs
- Person.cs
- PersonDTO.cs
- Extensions.cs
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>
This is the use of AutoGen in Program.cs
using mapperDemo;
var p=new Person();
p.FirstName = "Andrei";
p.LastName = "Ignat";
PersonDTO dto= p.ToDTO();
Console.WriteLine(dto.FullName);
This is the use of AutoGen in Person.cs
public class Person
{
public int ID { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
}
This is the use of AutoGen in PersonDTO.cs
using Antelcat.AutoGen.ComponentModel.Mapping;
namespace mapperDemo;
public class PersonDTO
{
public int ID { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
[MapIgnore]
public string FullName {
get
{
return FirstName + " " + LastName;
}
}
}
This is the use of AutoGen in Extensions.cs
using Antelcat.AutoGen.ComponentModel.Mapping;
namespace mapperDemo;
public static partial class Extensions
{
[AutoMap(Extra = [nameof(AfterMap)])]
public static partial PersonDTO ToDTO(this Person person);
private static void AfterMap(Person person, PersonDTO personDTO)
{
person.ID= personDTO.ID;
}
}
Generated Filesβ
Those are taken from $(BaseIntermediateOutputPath)\GX
- AutoMap__.mapperDemo.Extensions.g.cs
// <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