

























操作Enum的一些实用方法:
public static T GetEnumItem<T>(string name)
{
Type type = typeof(T);
if (Enum.IsDefined(type, name))
return (T)Enum.Parse(type, name, true);
if (Enum.IsDefined(type, "OTHERS"))
return (T)Enum.Parse(type, "OTHERS", true);
throw new ArgumentException();
}

public static string GetEnumName<T>(T value)
{
Type type = typeof(T);
return Enum.GetName(type, value);
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。