I have enum like this:
public enum ObectTypes
{
TypeOne,
TypeTwo,
TypeThree,
...
TypeTwenty
}
然后我需要将这个枚举转换为字符串。现在我是这样做的:
public string ConvertToCustomTypeName(ObjectTypes typeObj)
{
string result = string.Empty;
switch (typeObj)
{
case ObjectTypes.TypeOne: result = "This is type T123"; break;
case ObjectTypes.TypeTwo: result = "Oh man! This is type T234"; break;
...
case ObjectTypes.TypeTwenty: result = "This is type last"; break;
}
return result;
}
我相信有更好的方法来解决这个问题,我正在寻找一些好的实践方案。
编辑:结果字符串中没有固定模式。
提前感谢您。