操作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);
}

浙公网安备 33010602011771号