nagybalint001 / enum-constants

Generating string constants to a class from an enum type.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EnumConstants

license NuGet downloads

Generating string constants to a class from an enum type.

Sample code:

[AutoConstants(typeof(OtherSampleEnum))]
public partial class Sample
{
    [AutoConstants(typeof(SampleEnum), "Asd")]
    public partial class SubClass
    {
        [AutoConstants(typeof(SampleEnum))]
        public partial class SubSubClass
        {
        }
    }

    public void Foo()
    {
        var foo = Sample.Value2; // Value2
        var bar = Sample.SubClass.Value1; // AsdValue1
        var baz = Sample.SubClass.SubSubClass.Value2; // Value2
    }
}

public enum SampleEnum
{
    Value1,
    Value2,
    Value3,
}

public enum OtherSampleEnum
{
    Value1,
    Value2,
    Value3,
}

About

Generating string constants to a class from an enum type.

License:MIT License


Languages

Language:C# 100.0%