Exemplo n.º 1
0
        static void UnPackageValueNameValueCollection(KeyEntry keyEntry, Entry entry, byte[] buffer)
        {
            TreePackage package = Load(buffer);

            if (package == null || package.Count == 0)
            {
                entry.Value = new System.Collections.Specialized.NameValueCollection();//创建实际的数组类型
                return;
            }
            System.Collections.Specialized.NameValueCollection col = new System.Collections.Specialized.NameValueCollection();
            Entry entry2 = null;

            for (int index = 0; index < package.Count; index++)
            {
                entry2 = package.Entries[index.ToString()];
                string key = (string)entry2.Attributes["Key"];
                if (entry2.Value != null)
                {
                    foreach (string item in (string[])entry2.Value)
                    {
                        col.Add(key, item);
                    }
                }
            }
            entry.Value = col;
            package.Clear(false);
            package.Dispose();
            package = null;
        }
Exemplo n.º 2
0
        static void UnPackageValueIEnumerable(KeyEntry keyEntry, Entry entry, byte[] buffer, TreePackage treePackage)
        {
            if (treePackage.Version == 2)
            {
                if (entry.ArrayType == PackageArrayTypes.T_Array && entry.ValueType == PackageValueTypes.Byte)
                {
                    entry.Value = buffer;
                    return;
                }
            }
            TreePackage package = Load(buffer);
            Type        t1      = null;

            if (package.Attributes.ContainsKey("T1"))
            {
                t1 = FastWrapper.GetWarpperType((string)package.Attributes["T1"]);
            }
            UnPackageValueIEnumerableCreateArrayHandler createArrayHandler = null;
            UnPackageValueIEnumerableArrayAddHandler    addHandler         = null;

            System.Collections.IList array = null;
            Array array2 = null;

            switch (keyEntry.ArrayType)
            {
            case PackageArrayTypes.T_Array:
                createArrayHandler = (p1) => array2 = (Array)CreateTArray(keyEntry, p1, false, true, t1);
                addHandler         = (p1, p2) => array2.SetValue(p2, p1);
                break;

            case PackageArrayTypes.T_List:
                createArrayHandler = (p1) => CreateTArray(keyEntry, p1, true, true, t1);
                addHandler         = (p1, p2) => array.Add(p2);
                break;

            case PackageArrayTypes.Object_Array:
                createArrayHandler = (p1) => array2 = (Array)CreateTArray(keyEntry, p1, false, false, t1);
                addHandler         = (p1, p2) => array2.SetValue(p2, p1);
                break;

            case PackageArrayTypes.Object_List:
                createArrayHandler = (p1) => CreateTArray(keyEntry, p1, true, false, t1);
                addHandler         = (p1, p2) => array.Add(p2);
                break;

            default:
                throw new NotSupportedException("暂不支持“" + keyEntry.ArrayType + "”类型的数组。");
            }
            if (package == null || package.Count == 0)
            {
                entry.Value = createArrayHandler(0);//创建实际的数组类型
                return;
            }
            //创建数组
            array = createArrayHandler(package.Count);
            for (int index = 0; index < package.Count; index++)
            {
                addHandler(index, package[index.ToString()]);
            }
            entry.Value = array;
            package.Clear(false);
            package.Dispose();
            package = null;
        }