public override object CreateInstance(fsData data, Type storageType) { return(fsMetaType.Get(Serializer.Config, storageType).CreateInstance()); }
public override object CreateInstance(fsData data, Type storageType) { return(new AnimationCurve()); }
public override object CreateInstance(fsData data, Type storageType) { return(storageType); }
public override fsResult TryDeserialize(fsData storage, ref object instance, Type storageType) { var result = fsResult.Success; if (UseBool(storageType)) { if ((result += CheckType(storage, fsDataType.Boolean)).Succeeded) { instance = storage.AsBool; } return(result); } if (UseDouble(storageType) || UseInt64(storageType)) { if (storage.IsDouble) { instance = Convert.ChangeType(storage.AsDouble, storageType); } else if (storage.IsInt64) { instance = Convert.ChangeType(storage.AsInt64, storageType); } else if (Serializer.Config.Serialize64BitIntegerAsString && storage.IsString && (storageType == typeof(Int64) || storageType == typeof(UInt64))) { instance = Convert.ChangeType(storage.AsString, storageType); } else { return(fsResult.Fail(GetType().Name + " expected number but got " + storage.Type + " in " + storage)); } return(fsResult.Success); } if (UseString(storageType)) { if ((result += CheckType(storage, fsDataType.String)).Succeeded) { var str = storage.AsString; if (storageType == typeof(char)) { if (storageType == typeof(char)) { if (str.Length == 1) { instance = str[0]; } else { instance = default(char); } } } else { instance = str; } } return(result); } return(fsResult.Fail(GetType().Name + ": Bad data; expected bool, number, string, but got " + storage)); }
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) { // null is automatically serialized return(Serializer.TrySerialize(Nullable.GetUnderlyingType(storageType), instance, out serialized)); }
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) { // null is automatically deserialized return(Serializer.TryDeserialize(data, Nullable.GetUnderlyingType(storageType), ref instance)); }
/// <summary> /// Serialize the actual object into the given data storage. /// </summary> /// <param name="instance"> /// The object instance to serialize. This will never be null. /// </param> /// <param name="serialized">The serialized state.</param> /// <param name="storageType"> /// The field/property type that is storing this instance. /// </param> /// <returns>If serialization was successful.</returns> public abstract fsResult TrySerialize(object instance, out fsData serialized, Type storageType);
protected fsResult CheckKey(fsData data, string key, out fsData subitem) { return(CheckKey(data.AsDictionary, key, out subitem)); }
protected fsResult FailExpectedType(fsData data, params fsDataType[] types) { return(fsResult.Fail(GetType().Name + " expected one of " + string.Join(", ", types.Select(t => t.ToString()).ToArray()) + " but got " + data.Type + " in " + data)); }
/// <summary> /// Deserialize data into the object instance. /// </summary> /// <param name="data">Serialization data to deserialize from.</param> /// <param name="instance"> /// The object instance to deserialize into. /// </param> /// <param name="storageType"> /// The field/property type that is storing the instance. /// </param> /// <returns> /// True if serialization was successful, false otherwise. /// </returns> public abstract fsResult TryDeserialize(fsData data, ref object instance, Type storageType);
public override object CreateInstance(fsData data, Type storageType) { return(new InputAction()); }