private static string enumToString(Enum v) { string name = v.ToString(); FieldInfo field = v.GetType().GetField(name); if (field == null) { return(Convert.ToInt32(v).ToString()); } CaptionAttribute customAttribute = (CaptionAttribute)Attribute.GetCustomAttribute(field, typeof(CaptionAttribute)); string enumText = string.Empty; if (customAttribute != null) { enumText = customAttribute.GetEnumText(field); } else { enumText = LangTranslator.GetEnumText(field); } if (!string.IsNullOrEmpty(enumText)) { return(enumText); } if (customAttribute != null) { return(customAttribute.Text); } return(ConvertName(name)); }
public static string ForType(Type type, bool forceName) { CaptionAttribute customAttribute = (CaptionAttribute)Attribute.GetCustomAttribute(type, typeof(CaptionAttribute)); if (customAttribute != null) { return(customAttribute.Text); } if (!forceName) { return(null); } return(ConvertName(type.Name)); }
public static string ForPropertyInfo(PropertyInfo pi) { CaptionAttribute customAttribute = (CaptionAttribute)Attribute.GetCustomAttribute(pi, typeof(CaptionAttribute)); if (customAttribute != null) { return(customAttribute.Text); } customAttribute = (CaptionAttribute)Attribute.GetCustomAttribute(pi.PropertyType, typeof(CaptionAttribute)); if (customAttribute != null) { return(customAttribute.Text); } return(ConvertName(pi.Name)); }
public static string ForPropertyDescriptor(PropertyDescriptor pd, bool useName) { CaptionAttribute customAttribute = (CaptionAttribute)pd.Attributes[typeof(CaptionAttribute)]; if (customAttribute != null) { return(customAttribute.GetText(pd)); } customAttribute = (CaptionAttribute)Attribute.GetCustomAttribute(pd.PropertyType, typeof(CaptionAttribute)); if (customAttribute != null) { return(customAttribute.Text); } if (!useName) { return(null); } return(ConvertName(pd.Name)); }