How can I get an enum value from its description?

后端 未结 3 1056
梦如初夏
梦如初夏 2020-12-11 07:27

I have an enum representing all material assembly codes in the system:

public enum EAssemblyUnit
{
    [Description(\"UCAL1\")]
    eUCAL1,
    [Description(         


        
3条回答
  •  时光取名叫无心
    2020-12-11 08:07

    You could also use Humanizer for that. To get the description you can use:

    EAssemblyUnit.eUCAL1.Humanize();
    

    and to get the enum back from the description you can use

    "UCAL1".DehumanizeTo();
    

    Disclaimer: I am the creator of Humanizer.

提交回复
热议问题