Linking enum value with localized string resource

前端 未结 5 599
终归单人心
终归单人心 2021-01-02 18:15

Related: Get enum from enum attribute

I want the most maintainable way of binding an enumeration and it\'s associated localized string values to something.

5条回答
  •  滥情空心
    2021-01-02 18:29

    You could just crash immediately if someone doesn't update it correctly.

    public String GetString(SourceFilterOption option)
    {
        switch (option)
        {
            case SourceFilterOption.LastNumberOccurences:
                return CR.LAST_NUMBER_OF_OCCURANCES;
            case SourceFilterOption.LastNumberWeeks:
                return CR.LAST_NUMBER_OF_WEEKS;
            case SourceFilterOption.DateRange:
                return CR.DATE_RANGE;
            default:
                throw new Exception("SourceFilterOption " + option + " was not found");
        }
    }
    

提交回复
热议问题