Esempio n. 1
0
        // Duplicate an lpcvalue object
        public static LPCValue Duplicate(LPCValue val)
        {
            if (val.IsInt)
            {
                return(Create(val.AsInt));
            }
            else if (val.IsFloat)
            {
                return(Create(val.AsFloat));
            }
            else if (val.IsString)
            {
                return(Create(val.AsString));
            }
            else if (val.IsBuffer)
            {
                return(Create((byte[])val.AsBuffer.Clone()));
            }
            else if (val.IsArray)
            {
                LPCArray dupVal = LPCArray.Empty;

                foreach (LPCValue element in val.AsArray.Values)
                {
                    dupVal.Add(Duplicate(element));
                }

                return(LPCValue.Create(dupVal));
            }
            else if (val.IsMapping)
            {
                LPCMapping dupVal = LPCMapping.Empty;
                LPCMapping valMap = val.AsMapping;
                foreach (object key in valMap.Keys)
                {
                    if (key is int)
                    {
                        int keyInt = (int)key;
                        dupVal.Add(keyInt, Duplicate(valMap[keyInt]));
                        continue;
                    }
                    else if (key is string)
                    {
                        string keyStr = (string)key;
                        dupVal.Add(keyStr, Duplicate(valMap[keyStr]));
                        continue;
                    }
                    throw new Exception("Unexpected key type.");
                }
                return(LPCValue.Create(dupVal));
            }
            else
            {
                throw new Exception("Unexpected duplicated.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Append the specified array.
        /// </summary>
        public void Append(LPCMapping data)
        {
            foreach (object key in data.Keys)
            {
                // key为int
                if (key is int)
                {
                    this.Add((int)key, data[(int)key]);
                    continue;
                }

                // key为stirng
                if (key is string)
                {
                    this.Add((string)key, data[(string)key]);
                    continue;
                }
            }
        }
Esempio n. 3
0
        // Duplicate an lpcvalue object
        public static LPCValue Duplicate(LPCMapping val)
        {
            LPCMapping dupVal = new LPCMapping();

            foreach (object key in val.Keys)
            {
                if (key is int)
                {
                    int keyInt = (int)key;
                    dupVal.Add(keyInt, Duplicate(val[keyInt]));
                    continue;
                }
                else if (key is string)
                {
                    string keyStr = (string)key;
                    dupVal.Add(keyStr, Duplicate(val[keyStr]));
                    continue;
                }
                throw new Exception("Unexpected key type.");
            }

            // 返回数据
            return(LPCValue.Create(dupVal));
        }
Esempio n. 4
0
        /// <summary>
        /// 拷贝mapping到指定mapping中
        /// </summary>
        public void CopyTo(List <string> keyList, LPCMapping copyToMap)
        {
            // 没有数据
            if (_mapStr == null)
            {
                return;
            }

            LPCValue tValue;
            string   keyStr = string.Empty;

            // 逐个元素Copy
            for (int i = 0; i < keyList.Count; i++)
            {
                keyStr = keyList[i];
                if (!_mapStr.TryGetValue(keyStr, out tValue))
                {
                    continue;
                }

                // copy数据
                copyToMap.Add(keyStr, tValue);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 拷贝mapping
        /// </summary>
        public LPCMapping Copy()
        {
            LPCMapping dst = new LPCMapping();

            // 构建数据
            if (_mapInt != null)
            {
                foreach (int intKey in _mapInt.Keys)
                {
                    dst.Add(intKey, _mapInt[intKey]);
                }
            }

            if (_mapStr != null)
            {
                foreach (string strKey in _mapStr.Keys)
                {
                    dst.Add(strKey, _mapStr[strKey]);
                }
            }

            // 返回数据
            return(dst);
        }
Esempio n. 6
0
        /// <summary>
        /// 拷贝mapping到指定mapping中
        /// </summary>
        public void CopyTo(List <int> keyList, LPCMapping copyToMap)
        {
            // 没有数据
            if (_mapInt == null)
            {
                return;
            }

            LPCValue tValue;
            int      keyInt = 0;

            // 逐个元素Copy
            for (int i = 0; i < keyList.Count; i++)
            {
                keyInt = keyList[i];
                if (!_mapInt.TryGetValue(keyInt, out tValue))
                {
                    continue;
                }

                // copy数据
                copyToMap.Add(keyInt, tValue);
            }
        }