public static string GetPatternByProperties(FilePattern p) { Type enumType = p.GetType(); //得到enum的类型 FieldInfo[] fields = enumType.GetFields(); //获取enum下的所有共有字段 foreach (var field in fields) //遍历字段 { if (field.Name.Equals(p.ToString())) //判断出与arg相同的字段 { //获取该字段上的Pattern属性 object[] attributes = field.GetCustomAttributes(typeof(PatternAttribute), true); if (attributes.Length > 0) { return(((PatternAttribute)attributes[0]).Pattern); } } } return(string.Empty); }