This project's purpose is to provide repeat code generated from Source Generator
Nuget: SourceGenerator.Library
When install or update SourceGenerator.Library
, you need close and reopen IDE for intelligent.
This generator will generate appsettings.json top level key
to AppSettings.[Key]
.
Only simple types are supported.
Example:
{
"Test": "1",
"Test2": 2,
"Test3": true,
"Test4": {},
"Test5": [],
"Test6": null
}
Generated:
// Auto-generated code
namespace compilation
{
public class AppSettings
{
public const string Test = "1";
public const int Test2 = 2;
public const bool Test3 = True;
}
}
Test4 is object
, Test5 is array
, Test6 is null
, so it will be ignored.
This generator will auto generate constructor by field and need install SourceGenerator.Common
You can use ArgsAttribute
in class
or field
. When used in class, you can use ArgsIgnoreAttribute
to ignore field.
Target class must be public partial.
Only private
non-static
non-const
field is supported.
Example:
using SourceGenerator.Common;
namespace SourceGenerator.Demo
{
public partial class UserClass
{
[Args]
private string _test;
[Args]
private string _test2, _test3;
private const string test4;
}
[Args]
public partial class UserClass2
{
private string _test;
private string _test2, _test3;
private const string test4;
public string test5;
}
}
Generated:
// Auto-generated code
using SourceGenerator.Common;
namespace SourceGenerator.Demo
{
public partial class UserClass
{
public UserClass(string a0, string a1, string a2)
{
this._test = a0;
this._test2 = a1;
this._test3 = a2;
}
}
}
and
// Auto-generated code
using SourceGenerator.Common;
namespace SourceGenerator.Demo
{
public partial class UserClass2
{
public UserClass2(string a0, string a1, string a2)
{
this._test = a0;
this._test2 = a1;
this._test3 = a2;
}
}
}
This generator will auto generate property by field and need install SourceGenerator.Common
You can use PropertyAttribute
in field
.
Target class must be public partial.
Example:
using SourceGenerator.Common;
namespace SourceGenerator.Demo
{
public partial class UserClass
{
[Property]
private string _test;
[Property]
private string _test2, _test3;
private const string test4;
}
}
Generated:
// Auto-generated code
using SourceGenerator.Common;
namespace SourceGenerator.Demo
{
public partial class UserClass
{
public string Test { get => _test; set => _test = value; }
public string Test2 { get => _test2; set => _test2 = value; }
public string Test3 { get => _test3; set => _test3 = value; }
}
}