/// <summary> /// 数组集合结构的添加 /// </summary> /// <param name="item"></param> /// <returns></returns> public void Add(TItemType item) { switch (BaseType) { case StructType.NormalArray: NormalArray[++ArrayCount] = item; break; case StructType.Array: ArrayInstance.SetValue(item, ++ArrayCount); break; case StructType.ArrayList: ArrayListInstance.Add(item); break; case StructType.List: ListInstance.Add(item); break; default: throw new ArgumentOutOfRangeException(); } }
// 删除数组集合元素 public void Remove(TItemType item) { try { switch (BaseType) { case StructType.NormalArray: if (Array.IndexOf(NormalArray, item) != -1) { NormalArray[Array.IndexOf(NormalArray, item)] = default(TItemType); // for (var i = Array.IndexOf(NormalArray, item); i < ArrayCount - 1; i++) // NormalArray[i] = NormalArray[i + 1]; ArrayCount--; } else { var e = new StructShowControllerException("找不到元素!"); throw e; } break; case StructType.Array: if (Array.IndexOf(ArrayInstance, item) != -1) { ArrayInstance.SetValue(null, Array.IndexOf(ArrayInstance, item)); // for (var i = Array.IndexOf(ArrayInstance, item); i < ArrayCount - 1; i++) // ArrayInstance.SetValue(ArrayInstance.GetValue(i + 1), i); ArrayCount--; } else { var e = new StructShowControllerException("找不到元素!"); throw e; } break; case StructType.ArrayList: if (ArrayListInstance.Contains(item)) { ArrayListInstance.Remove(item); } else { var e = new StructShowControllerException("找不到元素!"); throw e; } break; case StructType.List: if (ListInstance.Contains(item)) { ListInstance.Remove(item); } else { var e = new StructShowControllerException("找不到元素!"); throw e; } break; case StructType.Dictionary: if (DictionaryInstance.ContainsValue(item)) { foreach (var comparable in DictionaryInstance) { if (comparable.Value.Equals(item)) { DictionaryInstance.Remove(comparable.Key); } } } else { var e = new StructShowControllerException("找不到元素!"); throw e; } break; case StructType.HashTable: if (HashTableInstance.ContainsValue(item)) { foreach (DictionaryEntry entry in HashTableInstance) { if (entry.Value.Equals(item)) { HashTableInstance.Remove(entry.Key); } } } else { var e = new StructShowControllerException("找不到元素!"); throw e; } break; default: throw new ArgumentOutOfRangeException(); } } catch (InvalidOperationException) { } }