// 删除键值对元素 public void RemoveKey(string key) { switch (BaseType) { case StructType.Dictionary: if (DictionaryInstance.ContainsKey(key)) { DictionaryInstance.Remove(key); } else { var e = new StructShowControllerException("找不到键!"); throw e; } break; case StructType.HashTable: if (HashTableInstance.ContainsKey(key)) { HashTableInstance.Remove(key); } else { var e = new StructShowControllerException("找不到键!"); throw e; } 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) { } }