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 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(); var defaultInstance = metaType.CreateInstance(); for (int i = 0; i < metaType.Properties.Length; ++i) { fsMetaProperty property = metaType.Properties[i]; if (property.CanRead == false) { continue; } if (fsGlobalConfig.SerializeDefaultValues == false) { if (Equals(property.Read(instance), property.Read(defaultInstance))) { 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); }
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()); //Dont do this for UnityObject. While there is fsUnityObjectConverter, this converter is also used as override, //when serializing a UnityObject directly. object defaultInstance = null; 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 (fsGlobalConfig.SerializeDefaultValues == false && defaultInstance != null) { if (Equals(property.Read(instance), property.Read(defaultInstance))) { continue; } } fsData serializedData; var itemResult = Serializer.TrySerialize(property.StorageType, null, property.Read(instance), out serializedData); result.AddMessages(itemResult); if (itemResult.Failed) { continue; } serialized.AsDictionary[property.JsonName] = serializedData; } return(result); }
public override object CreateInstance(fsData data, Type storageType) { fsMetaType metaType = fsMetaType.Get(Serializer.Config, storageType); return(metaType.CreateInstance()); }