Пример #1
0
        public void SerializeField(BinaryClassChunk element, string name)
        {
            ClassMember member = Editor.GetMember(this.GetType(), name);

            if (member == null)
            {
                return;
            }
            element.AddProperty(name, member.GetValue((object)this));
        }
 public bool Deserialize()
 {
     if (this._data == null)
     {
         this._result = DeserializeResult.NoData;
         return(false);
     }
     if (this._result == DeserializeResult.Success)
     {
         return(true);
     }
     try
     {
         this._data.position = (int)this._offset;
         ushort num1 = this._data.ReadUShort();
         for (int index = 0; index < (int)num1; ++index)
         {
             string      str         = this._data.ReadString();
             ClassMember classMember = (ClassMember)null;
             System.Type key         = (System.Type)null;
             if (str.StartsWith("@"))
             {
                 if (this._extraProperties == null)
                 {
                     this._extraProperties = new MultiMap <string, object>();
                 }
                 byte num2 = this._data.ReadByte();
                 if (((int)num2 & 1) != 0)
                 {
                     byte num3 = (byte)((uint)num2 >> 1);
                     BinaryClassMember.typeMap.TryGetKey(num3, out key);
                 }
                 else
                 {
                     key = Editor.GetType(this._data.ReadString());
                 }
                 str = str.Substring(1, str.Length - 1);
             }
             else
             {
                 classMember = Editor.GetMember(this.GetType(), str);
                 if (classMember != null)
                 {
                     key = classMember.type;
                 }
             }
             uint num4 = this._data.ReadUInt();
             if (key != (System.Type)null)
             {
                 int position = this._data.position;
                 if (typeof(BinaryClassChunk).IsAssignableFrom(key))
                 {
                     BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(key, this._data, root: false);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)binaryClassChunk);
                     }
                     else
                     {
                         this._headerDictionary[str] = binaryClassChunk;
                     }
                     this._data.position = position + (int)num4;
                 }
                 else if (key.IsArray)
                 {
                     Array array = this.DeserializeArray(key, key.GetElementType(), this._data);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)array);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)array);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(List <>))
                 {
                     Array array    = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance = Activator.CreateInstance(key) as IList;
                     foreach (object obj in array)
                     {
                         instance.Add(obj);
                     }
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)instance);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)instance);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(HashSet <>))
                 {
                     Array array     = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance1 = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(key.GetGenericArguments()[0]));
                     foreach (object obj in array)
                     {
                         instance1.Add(obj);
                     }
                     object instance2 = Activator.CreateInstance(key, (object)instance1);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, instance2);
                     }
                     else
                     {
                         classMember.SetValue((object)this, instance2);
                     }
                 }
                 else
                 {
                     object element = !key.IsEnum ? this._data.Read(key, false) : (object)this._data.ReadInt();
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, element);
                     }
                     else
                     {
                         classMember.SetValue((object)this, element);
                     }
                 }
             }
             else
             {
                 this._data.position += (int)num4;
             }
         }
     }
     catch (Exception ex)
     {
         this._exception = ex;
         this._result    = DeserializeResult.ExceptionThrown;
         return(false);
     }
     this._result = DeserializeResult.Success;
     return(true);
 }