private static void SetNewInstanceByTextAsset(TextAsset asset) { if ((asset != null) && (_instance == null)) { _instance = BuildDictionaryTextAssetInstance(asset); } }
public object Call(Interpreter interpreter, Token token, List arguments) { if (!(arguments[0] is DictionaryInstance)) { throw new ErrorHandler.RuntimeError(token, "Expected a Dictionary instance"); } DictionaryInstance rhs = (DictionaryInstance)arguments[0]; Dict resultsDict = new Dict(); foreach (Pair kvp in self.container) { resultsDict[kvp.Key] = kvp.Value; } foreach (Pair kvp in rhs.container) { if (!resultsDict.ContainsKey(kvp.Key)) { resultsDict[kvp.Key] = kvp.Value; } } return(new DictionaryInstance(resultsDict)); }
/// <summary> /// 对键值对的键部分逆序排序 /// </summary> public void ReverseSortKey() { switch (BaseType) { case StructType.Dictionary: DictionaryInstance = DictionaryInstance.OrderByDescending(dict => dict.Key) .ToDictionary(dict => dict.Key, dict => dict.Value); break; case StructType.HashTable: var temp = new List <string>(); var strings = new string[30]; HashTableInstance.Keys.CopyTo(strings, 0); // 转换为列表排序 temp = strings.ToList(); temp.Sort(); var hash = new Hashtable(); foreach (var key in temp) { if (key != null) { hash.Add(key, HashTableInstance[key]); } } HashTableInstance = hash; break; default: throw new ArgumentOutOfRangeException(); } }
// 删除键值对元素 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 object Call(Interpreter interpreter, Token token, List arguments) { if (!(arguments[0] is DictionaryInstance)) { throw new ErrorHandler.RuntimeError(token, "Expected a Dictionary instance"); } DictionaryInstance rhs = (DictionaryInstance)arguments[0]; if (self.container.Count != rhs.container.Count) { return(false); } foreach (Pair kvp in self.container) //NOTE: I'm a little worried about key comparison { if (!rhs.container.ContainsKey(kvp.Key)) { return(false); } if (!interpreter.CheckIsEqual(kvp.Value, rhs.container[kvp.Key])) { return(false); } } return(true); }
public static DictionaryInstance Instance() { if (_instance != null) { return(_instance); } else { _instance = createNewInstance(); return(_instance); } }
/// <summary> /// 键值对的添加 /// </summary> /// <param name="key">键</param> /// <param name="item">值</param> /// <returns></returns> public void Add(string key, TItemType item) { switch (BaseType) { case StructType.Dictionary: DictionaryInstance.Add(key, item); break; case StructType.HashTable: HashTableInstance.Add(key, item); break; default: throw new ArgumentOutOfRangeException(); } }
public Concat(DictionaryInstance self) { this.self = self; }
public Reduce(DictionaryInstance self) { this.self = self; }
public ContainsValue(DictionaryInstance self) { this.self = self; }
public ContainsKey(DictionaryInstance self) { this.self = self; }
public Length(DictionaryInstance self) { this.self = self; }
public Delete(DictionaryInstance self) { this.self = self; }
public Insert(DictionaryInstance self) { this.self = self; }
public Clear(DictionaryInstance self) { this.self = self; }
public EqualsCallable(DictionaryInstance self) { this.self = self; }
public Any(DictionaryInstance self) { this.self = self; }
public ToStringCallable(DictionaryInstance self) { this.self = self; }
public Filter(DictionaryInstance self) { this.self = self; }
// 删除数组集合元素 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) { } }
public ForEach(DictionaryInstance self) { this.self = self; }
public Map(DictionaryInstance self) { this.self = self; }
static Dictionary() { _instance = Instance(); }