/// <summary> /// 将尺寸配置转换为<seealso cref="ListItem"/>对象 /// </summary> /// <param name="selected">是否选中</param> /// <returns></returns> public ListItem ToListItem(bool selected = false) { ListItem item = new ListItem { Text = SizeName, Value = Enum.GetName(typeof(ImageSizeEnum), _Size), Selected = selected }; return item; }
/// <summary> /// 获取枚举类型的列表值 /// </summary> /// <param name="oEnumType">枚举类型</param> /// <param name="nSelectedIndex">选中的项</param> /// <returns>符合MVC页面要求的ListItem列表值(多语言)</returns> public List<ListItem> SelectEnumList(Type oEnumType, byte nSelectedIndex) { List<ListItem> oList = new List<ListItem>(); string[] sKeys = Enum.GetNames(oEnumType); int keysLength = sKeys.Length; string[] sNames = LiveAzure.Resource.Common.ResourceManager.GetString(oEnumType.Name).Split(','); int namesLength = sNames.Length; for (byte i = 0; i < keysLength; i++) { ListItem newItem = new ListItem { Selected = (i == nSelectedIndex), Text = (i < namesLength) ? sNames[i].Trim() : sKeys[i], Value = i.ToString() }; oList.Add(newItem); } return oList; }