Пример #1
0
        public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            var result = fsResult.Success;

            // Verify that we actually have an Object
            if ((result += CheckType(data, fsDataType.Object)).Failed)
            {
                return(result);
            }

            if (data.AsDictionary.Count == 0)
            {
                return(fsResult.Success);
            }

            //
            fsMetaType metaType = fsMetaType.Get(Serializer.Config, storageType);

            metaType.EmitAotData();

            for (int i = 0; i < metaType.Properties.Length; ++i)
            {
                fsMetaProperty property = metaType.Properties[i];
                if (property.CanWrite == false)
                {
                    continue;
                }

                fsData propertyData;
                if (data.AsDictionary.TryGetValue(property.JsonName, out propertyData))
                {
                    object deserializedValue = null;

/*
 *                  // We have to read in the existing value, since we need to support partial
 *                  // deserialization. However, this is bad for perf.
 *                  // TODO: Find a way to avoid this call when we are not doing a partial deserialization
 *                  //       Maybe through a new property, ie, Serializer.IsPartialSerialization, which just
 *                  //       gets set when starting a new serialization? We cannot pipe the information
 *                  //       through CreateInstance unfortunately.
 *                  if (property.CanRead) {
 *                      deserializedValue = property.Read(instance);
 *                  }
 */
                    // 递归下去
                    var itemResult = Serializer.TryDeserialize(propertyData, property.StorageType,
                                                               property.OverrideConverterType, ref deserializedValue);
                    result.AddMessages(itemResult);
                    if (itemResult.Failed)
                    {
                        continue;
                    }

                    // 往instance的property写入deserializedValue数据
                    property.Write(instance, deserializedValue);
                }
            }

            return(result);
        }
        public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
        {
            serialized = fsData.CreateDictionary();
            var result = fsResult.Success;

            fsMetaType metaType = fsMetaType.Get(Serializer.Config, instance.GetType());

            metaType.EmitAotData();

            for (int i = 0; i < metaType.Properties.Length; ++i)
            {
                fsMetaProperty property = metaType.Properties[i];
                if (property.CanRead == false)
                {
                    continue;
                }

                fsData serializedData;

                var itemResult = Serializer.TrySerialize(property.StorageType, property.OverrideConverterType,
                                                         property.Read(instance), out serializedData);
                result.AddMessages(itemResult);
                if (itemResult.Failed)
                {
                    continue;
                }

                serialized.AsDictionary[property.JsonName] = serializedData;
            }

            return(result);
        }
Пример #3
0
        public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
        {
            // 传进来的serialized 直接赋值一个Dict
            serialized = fsData.CreateDictionary();
            var result = fsResult.Success;

            // Serializer.Config 就是一些配置
            fsMetaType metaType = fsMetaType.Get(Serializer.Config, instance.GetType());

            metaType.EmitAotData();

            //PARADOXNOTION ADDITION
            object defaultInstance = null;

            //Dont do this for UnityObject. While there is fsUnityObjectConverter, this converter is also used as override,
            //when serializing a UnityObject directly.
            if (fsGlobalConfig.SerializeDefaultValues == false && !(instance is UnityEngine.Object))
            {
                defaultInstance = metaType.CreateInstance();
            }
            //

            for (int i = 0; i < metaType.Properties.Length; ++i)
            {
                fsMetaProperty property = metaType.Properties[i];
                // 不可读的跳过
                if (property.CanRead == false)
                {
                    continue;
                }

                // 如果是不存储默认值的情况
                //PARADOXNOTION ADDITION
                if (fsGlobalConfig.SerializeDefaultValues == false && defaultInstance != null)
                {
                    if (Equals(property.Read(instance), property.Read(defaultInstance)))
                    {
                        continue;
                    }
                }
                //

                fsData serializedData;

                // property.Read(instance) 理解为从某一个实例读取某一个属性,字段值
                var itemResult = Serializer.TrySerialize(property.StorageType, property.OverrideConverterType,
                                                         property.Read(instance), out serializedData);
                result.AddMessages(itemResult);
                if (itemResult.Failed)
                {
                    continue;
                }

                serialized.AsDictionary[property.JsonName] = serializedData;
            }

            return(result);
        }
        public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            var result = fsResult.Success;

            // Verify that we actually have an Object
            if ((result += CheckType(data, fsDataType.Object)).Failed)
            {
                return(result);
            }

            fsMetaType metaType = fsMetaType.Get(Serializer.Config, storageType);

            metaType.EmitAotData(/*throwException:*/ false);

            for (int i = 0; i < metaType.Properties.Length; ++i)
            {
                fsMetaProperty property = metaType.Properties[i];
                if (property.CanWrite == false)
                {
                    continue;
                }

                fsData propertyData;
                if (data.AsDictionary.TryGetValue(property.JsonName, out propertyData))
                {
                    object deserializedValue = null;

                    // We have to read in the existing value, since we need to
                    // support partial deserialization. However, this is bad for
                    // perf.

                    //       a partial deserialization Maybe through a new
                    //       property, ie, Serializer.IsPartialSerialization,
                    //       which just gets set when starting a new
                    //       serialization? We cannot pipe the information
                    //       through CreateInstance unfortunately.
                    if (property.CanRead)
                    {
                        deserializedValue = property.Read(instance);
                    }

                    var itemResult = Serializer.TryDeserialize(propertyData, property.StorageType,
                                                               property.OverrideConverterType, ref deserializedValue);
                    result.AddMessages(itemResult);
                    if (itemResult.Failed)
                    {
                        continue;
                    }

                    property.Write(instance, deserializedValue);
                }
            }

            return(result);
        }
Пример #5
0
        // Token: 0x06000466 RID: 1126 RVA: 0x0001C52C File Offset: 0x0001A72C
        public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            fsResult fsResult = fsResult.Success;
            fsResult fsResult2;

            fsResult = (fsResult2 = fsResult + base.CheckType(data, fsDataType.Object));
            if (fsResult2.Failed)
            {
                return(fsResult);
            }
            fsMetaType fsMetaType = fsMetaType.Get(this.Serializer.Config, storageType);

            fsMetaType.EmitAotData();
            for (int i = 0; i < fsMetaType.Properties.Length; i++)
            {
                fsMetaProperty property = fsMetaType.Properties[i];
                if (property.CanWrite)
                {
                    fsData data2;
                    if (data.AsDictionary.TryGetValue(property.JsonName, out data2))
                    {
                        int referenceId = fsBaseConverter.GetReferenceId(data2);
                        if (referenceId != -1 && this.Serializer.IsObjectVersionedAndUnderConstruction(referenceId))
                        {
                            object temp = instance;
                            this.Serializer.WhenInstanceCreated(referenceId, delegate(object refObject)
                            {
                                property.Write(temp, refObject);
                            });
                        }
                        else
                        {
                            object value = null;
                            if (property.CanRead)
                            {
                                value = property.Read(instance);
                            }
                            fsResult result = this.Serializer.TryDeserialize(data2, property.StorageType, property.OverrideConverterType, ref value);
                            fsResult.AddMessages(result);
                            if (!result.Failed)
                            {
                                property.Write(instance, value);
                            }
                        }
                    }
                }
            }
            return(fsResult);
        }
Пример #6
0
        public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            var result = fsResult.Success;

            // Verify that we actually have an Object
            if ((result += CheckType(data, fsDataType.Object)).Failed)
            {
                return(result);
            }

            fsMetaType metaType = fsMetaType.Get(storageType);

            metaType.EmitAotData();

            for (int i = 0; i < metaType.Properties.Length; ++i)
            {
                fsMetaProperty property = metaType.Properties[i];
                if (property.CanWrite == false)
                {
                    continue;
                }

                fsData propertyData;
                if (data.AsDictionary.TryGetValue(property.JsonName, out propertyData))
                {
                    object deserializedValue = null;

                    var itemResult = Serializer.TryDeserialize(propertyData, property.StorageType, ref deserializedValue);
                    result.AddMessages(itemResult);
                    if (itemResult.Failed)
                    {
                        continue;
                    }

                    property.Write(instance, deserializedValue);
                }
            }

            return(result);
        }
Пример #7
0
        // Token: 0x06000465 RID: 1125 RVA: 0x0001C470 File Offset: 0x0001A670
        public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
        {
            serialized = fsData.CreateDictionary();
            fsResult   success    = fsResult.Success;
            fsMetaType fsMetaType = fsMetaType.Get(this.Serializer.Config, instance.GetType());

            fsMetaType.EmitAotData();
            for (int i = 0; i < fsMetaType.Properties.Length; i++)
            {
                fsMetaProperty fsMetaProperty = fsMetaType.Properties[i];
                if (fsMetaProperty.CanRead)
                {
                    fsData   value;
                    fsResult result = this.Serializer.TrySerialize(fsMetaProperty.StorageType, fsMetaProperty.OverrideConverterType, fsMetaProperty.Read(instance), out value);
                    success.AddMessages(result);
                    if (!result.Failed)
                    {
                        serialized.AsDictionary[fsMetaProperty.JsonName] = value;
                    }
                }
            }
            return(success);
        }