Esempio n. 1
0
 public static object DeserializeArray(byte[] data, Type t)
 {
     t = t.GetElementType();
     if (((data != null) ? data.Length : 0) != 0)
     {
         Array array = null;
         using (MemoryStream input = new MemoryStream(data, false))
         {
             using (BinaryReader binaryReader = new BinaryReader(input))
             {
                 int num = binaryReader.ReadInt32();
                 array = Array.CreateInstance(t, num);
                 for (int i = 0; i < num; i++)
                 {
                     int    num2   = binaryReader.ReadInt32();
                     byte[] array2 = new byte[num2];
                     binaryReader.Read(array2, 0, num2);
                     object value = BloxSerializer.Deserialize(array2, t);
                     array.SetValue(value, i);
                 }
                 return(array);
             }
         }
     }
     return(Array.CreateInstance(t, 0));
 }
Esempio n. 2
0
        public static object DeserializeList(byte[] data, Type t)
        {
            IList list = (IList)Activator.CreateInstance(t);

            if (((data != null) ? data.Length : 0) != 0)
            {
                t = t.GetGenericArguments()[0];
                using (MemoryStream input = new MemoryStream(data, false))
                {
                    using (BinaryReader binaryReader = new BinaryReader(input))
                    {
                        int num = binaryReader.ReadInt32();
                        for (int i = 0; i < num; i++)
                        {
                            int    num2  = binaryReader.ReadInt32();
                            byte[] array = new byte[num2];
                            binaryReader.Read(array, 0, num2);
                            object value = BloxSerializer.Deserialize(array, t);
                            list.Add(value);
                        }
                        return(list);
                    }
                }
            }
            return(list);
        }
Esempio n. 3
0
        public BloxBlock CreateBlock()
        {
            if (string.IsNullOrEmpty(this.blockSysType))
            {
                return(null);
            }
            Type type = Type.GetType(this.blockSysType);

            if (type == null)
            {
                Debug.LogError("Could not find Block type: " + this.blockSysType);
                return(null);
            }
            BloxBlock bloxBlock = (BloxBlock)Activator.CreateInstance(type);

            bloxBlock.blockType    = this.blockType;
            bloxBlock.ident        = this.ident;
            bloxBlock.active       = this.active;
            bloxBlock._ed_viewOffs = this._ed_viewOffs;
            bloxBlock.returnType   = (string.IsNullOrEmpty(this.returnType) ? null : Type.GetType(this.returnType));
            if (bloxBlock.returnType != null)
            {
                bloxBlock.returnValue = BloxSerializer.Deserialize(this.returnValue, bloxBlock.returnType);
            }
            if (!string.IsNullOrEmpty(this.memberName))
            {
                Type type2 = string.IsNullOrEmpty(this.memberReflectedType) ? null : Type.GetType(this.memberReflectedType);
                if (type2 != null)
                {
                    if (this.memberType == MemberTypes.Field)
                    {
                        bloxBlock.mi = new BloxMemberInfo(type2.GetField(this.memberName, BloxBlockData.BindFlags), type2);
                    }
                    else if (this.memberType == MemberTypes.Property)
                    {
                        bloxBlock.mi = new BloxMemberInfo(type2.GetProperty(this.memberName, BloxBlockData.BindFlags), type2);
                    }
                    else if (this.memberType == MemberTypes.Constructor)
                    {
                        if (((this.paramTypes != null) ? this.paramTypes.Length : 0) != 0)
                        {
                            Type[] array = null;
                            array = new Type[this.paramTypes.Length];
                            for (int i = 0; i < this.paramTypes.Length; i++)
                            {
                                array[i] = Type.GetType(this.paramTypes[i]);
                            }
                            bloxBlock.mi = new BloxMemberInfo(type2.GetConstructor(BloxBlockData.CtorBindFlags, null, array, null), type2);
                        }
                        else
                        {
                            bloxBlock.mi = new BloxMemberInfo(type2.GetConstructor(Type.EmptyTypes), type2);
                        }
                    }
                    else if (this.memberType == MemberTypes.Method)
                    {
                        if (((this.paramTypes != null) ? this.paramTypes.Length : 0) != 0)
                        {
                            Type[] array2 = null;
                            array2 = new Type[this.paramTypes.Length];
                            for (int j = 0; j < this.paramTypes.Length; j++)
                            {
                                array2[j] = Type.GetType(this.paramTypes[j]);
                            }
                            bloxBlock.mi = new BloxMemberInfo(type2.GetMethod(this.memberName, BloxBlockData.BindFlags, null, array2, null), type2);
                        }
                        else
                        {
                            bloxBlock.mi = new BloxMemberInfo(type2.GetMethod(this.memberName, BloxBlockData.BindFlags, null, new Type[0], null), type2);
                        }
                    }
                }
            }
            if (((type != typeof(BloxBlock)) ? this.fields.Length : 0) != 0)
            {
                FieldInfo[] array3 = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
                for (int k = 0; k < this.fields.Length; k++)
                {
                    if (((this.fields[k].data != null) ? this.fields[k].data.Length : 0) != 0)
                    {
                        FieldInfo fieldInfo = null;
                        if (k < array3.Length && array3[k].Name == this.fields[k].fieldName)
                        {
                            fieldInfo = array3[k];
                        }
                        else
                        {
                            int num = 0;
                            while (num < array3.Length)
                            {
                                if (!(array3[num].Name == this.fields[k].fieldName))
                                {
                                    num++;
                                    continue;
                                }
                                fieldInfo = array3[num];
                                break;
                            }
                        }
                        if (fieldInfo != null)
                        {
                            Type type3 = Type.GetType(this.fields[k].typeName);
                            if (type3 != null && type3 == fieldInfo.FieldType)
                            {
                                object obj = BloxSerializer.Deserialize(this.fields[k].data, type3);
                                if (obj != null)
                                {
                                    fieldInfo.SetValue(bloxBlock, obj);
                                }
                            }
                        }
                    }
                }
            }
            return(bloxBlock);
        }