public ItemCache(List <ResPickListItem> list) { if (list.Count > 0) { _pickListId = list[0].PickListId; } _items = list; _idItemDict = new Dictionary <long, ResPickListItem>(list.Count); _nameIdDict = new Dictionary <string, long>(list.Count); // 临时变量 ss 和 s 无实际用处,可能在预定义字典的时候冲突时,可以在调试状态下检测 // 冲突的提示。 List <string> ss = new List <string>(); foreach (ResPickListItem item in list) { try { if (item.IsDefault) { _defaultItem = item; } _idItemDict.Add(item.PickListItemId, item); _nameIdDict.Add(item.Name, item.PickListItemId); } catch // (Exception ex) { ss.Add(item.Name); } } string s = String.Join(",", ss.ToArray()); }
private void AddItemToList(List <ResPickListItem> list, long strengthenValue, long baseId, string[] items, string[] code, string defaultItem) { for (int i = 0, len = items.Length; i < len; i++) { ResPickListItem item = new ResPickListItem(items[i], strengthenValue) { PickListItemId = baseId++ }; if (code != null) { item.Code = code[i]; } if (item.Name == defaultItem) { item.IsDefault = true; } list.Add(item); } }
private List <ResPickListItem> FromArray(long strengthenValue, string[] itemNames, string[] codes, string defaultItem) { List <ResPickListItem> items = new List <ResPickListItem>(); for (int i = 0, len = itemNames.Length; i < len; i++) { ResPickListItem item = new ResPickListItem(itemNames[i], strengthenValue); if (codes != null) { item.Code = codes[i]; } if (item.Name == defaultItem) { item.IsDefault = true; } items.Add(item); } return(items); }