Beispiel #1
0
 private static void SetNewInstanceByTextAsset(TextAsset asset)
 {
     if ((asset != null) && (_instance == null))
     {
         _instance = BuildDictionaryTextAssetInstance(asset);
     }
 }
Beispiel #2
0
                    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();
            }
        }
Beispiel #5
0
                    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);
                    }
Beispiel #6
0
 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();
            }
        }
Beispiel #8
0
 public Concat(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #9
0
 public Reduce(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #10
0
 public ContainsValue(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #11
0
 public ContainsKey(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #12
0
 public Length(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #13
0
 public Delete(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #14
0
 public Insert(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #15
0
 public Clear(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #16
0
 public EqualsCallable(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #17
0
 public Any(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #18
0
 public ToStringCallable(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #19
0
 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)
            {
            }
        }
Beispiel #21
0
 public ForEach(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #22
0
 public Map(DictionaryInstance self)
 {
     this.self = self;
 }
Beispiel #23
0
 static Dictionary()
 {
     _instance = Instance();
 }