/// <summary> /// Creates an array of list item according to the enum values. /// </summary> /// <returns>an array of list item.</returns> public static EnumListItem <T>[] GetListItems() { Type enumType = typeof(T); if (!enumType.IsEnum) { throw new ArgumentException("Not an enum type: " + enumType.Name, "T"); } List <EnumListItem <T> > enumValues = new List <EnumListItem <T> >(); StringResources stringResource = null; foreach (FieldInfo field in enumType.GetFields(BindingFlags.Public | BindingFlags.Static)) { T val = (T)field.GetValue(null); string desc = null; string descId = GetDescriptionID(field); if (descId != null) { // find localized text if (stringResource != null) { desc = stringResource.GetString(descId); } else { string textFound; StringResources res = FindStringResource(enumType, descId, out textFound); if (res != null) { stringResource = res; desc = textFound; } } } if (desc == null) { // fallback desc = field.Name; } enumValues.Add(new EnumListItem <T>(val, desc)); } return(enumValues.ToArray()); }
private string LoadString(string id) { string t = _strResource.GetString(id); return(t == null? id : t); }