ardalis/SmartEnum

Add source generator

开放

#259 创建于 2022年4月18日

 (7 条评论) (5 个反应) (0 位负责人)C# (185 个派生)github user discovery
enhancementgood first issuehelp wanted

仓库指标

星标
 (2,420 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

This could be improved further with source generators:

Allowing you to just decorate a partial class like so:

using Ardalis.SmartEnum;

[SmartEnum]
public sealed partial class TestEnum
{
    [EnumMember]
    public static readonly TestEnum One;

    [EnumMember]
    public static readonly TestEnum Two;

    [EnumMember]
    public static readonly TestEnum Three;
}

Generated code:

using Ardalis.SmartEnum;

sealed partial class TestEnum : SmartEnum<TestEnum>
{
    private TestEnum(string name, int value) : base(name, value)
    {
        One = new TestEnum(nameof(One), 1);
        Two = new TestEnum(nameof(Two), 2);
        Three = new TestEnum(nameof(Three), 3);
    }
}

贡献者指南