https://github.com/antelcat/autogen
Auto generate anything
https://github.com/antelcat/autogen
autogen compile-time extension mapping metadata polyfill roslyn roslyn-generator weaver
Last synced: 5 days ago
JSON representation
Auto generate anything
- Host: GitHub
- URL: https://github.com/antelcat/autogen
- Owner: Antelcat
- License: mit
- Created: 2023-12-06T09:53:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-08T14:32:56.000Z (8 days ago)
- Last Synced: 2025-07-08T15:42:03.988Z (8 days ago)
- Topics: autogen, compile-time, extension, mapping, metadata, polyfill, roslyn, roslyn-generator, weaver
- Language: C#
- Homepage:
- Size: 1.44 MB
- Stars: 24
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Antelcat.AutoGen
π¨π³ [δΈζ](./README.zh.md)
Auto generate anything you may want
> ~~unless we can't~~## Supported
### `Antelcat.AutoGen.ComponentModel` :
+ `Diagnostic`
+ #### `[MetadataScript]`Auto generate code executed by `Execute`

+ #### `[AutoMetadataFrom(Type, MemberTypes)]` :
Auto generate code using `Template` from target type members
+ #### `[AutoTypeInference]` :
Auto generate `Type` detected from `anonymous`object creation
+ #### `[RecordIgnore]` :
Auto exclude member calculation in `GetHashCode` and `PrintMembers` of record+ #### `[AutoStringTo(string, Accessibility)]` :
Auto generate string To extension
only on `assembly` and `static 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 is `ref readonly struct````csharp
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
```csharp
[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();
```+ #### `[AutoExtendFor]`:
Auto generate `this` extensions for `static` method in `static class`
```csharp
class StaticClass
{
public static void Fun(int i) => Console.WriteLine(i);
}
[AutoExtendFor(typeof(StaticClass))]
static partial class Extension;
///
static partial class Extension
{
public static void Fun(this int i) => StaticClass.Fun(i); // call original method
}+ #### `[AutoKeyAccessor]`:
Auto generate `object this[string key]` accessor
```csharp
[AutoKeyAccessor]
class Foo
{
public bool Property { get; set; }
}
///
partial class Foo
{
public object? this[string key]
{
get
{
switch (key)
{
case nameof(this.Property): return this.Property;
}
return null;
};
set
{
switch (key)
{
case nameof(this.Property): this.Property = (bool)value; break;
}
};
}
}
```+ #### `[AutoUnmamagedArray]`
Auto generate user defined length of array items, usually for `Marshal`
```csharp
[AutoUnmamagedArray(nameof(T), 4)]
struct CharArray where T : unmanaged{}
///
struct CharArray where T : unmanaged
{
public T item0;
public T item1;
public T item2;
public T item3;
public IEnumerable Enumerate(){
yield return item0;
yield return item1;
yield return item2;
yield return item3;
}
}
```+ #### `[AutoExtractInterface]`
Auto generate interface for specified type
like :

will generate
