110,539
社区成员
发帖
与我相关
我的任务
分享
public static class Extensions
{
public static string ToString(this eFileType e, int flag)
{
switch (flag)
{
case 0:
return e.ToString().TrimStart("eFT_".ToArray());
default:
return e.ToString();
}
}
}
Console.WriteLine(eFileType.eFT_dll.ToString(0));
public enum eFileType{
[Description("exe")]eFT_exe,
[Description("dll")]eFT_dll,
[Description("txt")]eFT_txt
}
public string GetChartset(eFileType filetype)
{
FieldInfo fi = filetype.GetType().GetField(filetype.ToString());
DescriptionAttribute[] descriptions =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute), false);
if (descriptions == null || descriptions.Length < 1)
{
throw new Exception("MailCharset type error.") ;
}
return descriptions[0].Description ;
}