}
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
- DescriptionAttribute[] attributes =
+ if (fieldInfo != null)
+ {
+ DescriptionAttribute[] attributes =
(DescriptionAttribute[])fieldInfo.GetCustomAttributes(
typeof(DescriptionAttribute), false);
- return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
+ return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
+ }
+
+ return string.Empty;
}
/// <summary>
}
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
- DisplayName[] attributes = (DisplayName[])fieldInfo.GetCustomAttributes(typeof(DisplayName), false);
+ if (fieldInfo != null)
+ {
+ DisplayName[] attributes = (DisplayName[])fieldInfo.GetCustomAttributes(typeof(DisplayName), false);
+
+ return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ }
- return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ return string.Empty;
}
/// <summary>
}
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
- ShortName[] attributes = (ShortName[])fieldInfo.GetCustomAttributes(typeof(ShortName), false);
+ if (fieldInfo != null)
+ {
+ ShortName[] attributes = (ShortName[])fieldInfo.GetCustomAttributes(typeof(ShortName), false);
+ return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ }
- return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ return string.Empty;
}
/// <summary>
{
var strings = new Collection<string>();
foreach (T e in Enum.GetValues(enumType))
+ {
strings.Add(GetDisplay(e));
+ }
+
return strings;
}