Enum ToString with user friendly strings

后端 未结 23 2066
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 11:44

My enum consists of the following values:

private enum PublishStatusses{
    NotCompleted,
    Completed,
    Error
};

I want to be able to

23条回答
  •  迷失自我
    2020-11-22 12:24

    Maybe I'm missing something, but what's wrong with Enum.GetName?

    public string GetName(PublishStatusses value)
    {
        return Enum.GetName(typeof(PublishStatusses), value)
    }
    

    edit: for user-friendly strings, you need to go through a .resource to get internationalisation/localisation done, and it would arguably be better to use a fixed key based on the enum key than a decorator attribute on the same.

提交回复
热议问题