public Type ResolveExpandedType() { if (RuntimeCodebase.TryDeserializeType(GetExpandedTypeName(), out var type)) { return(type); } return(null); }
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) { if (data.IsString == false) { return(fsResult.Fail("Type converter requires a string")); } if (RuntimeCodebase.TryDeserializeType(data.AsString, out var type)) { instance = type; } else { return(fsResult.Fail($"Unable to find type: '{data.AsString ?? "(null)"}'.")); } return(fsResult.Success); }
private fsResult InternalDeserialize_3_Inheritance(Type overrideConverterType, fsData data, Type storageType, ref object result, out List <fsObjectProcessor> processors) { var deserializeResult = fsResult.Success; var objectType = storageType; // If the serialized state contains type information, then we need to // make sure to update our objectType and data to the proper values // so that when we construct an object instance later and run // deserialization we run it on the proper type. if (IsTypeSpecified(data)) { var typeNameData = data.AsDictionary[Key_InstanceType]; // we wrap everything in a do while false loop so we can break // out it do { if (typeNameData.IsString == false) { deserializeResult.AddMessage(Key_InstanceType + " value must be a string (in " + data + ")"); break; } var typeName = typeNameData.AsString; if (!RuntimeCodebase.TryDeserializeType(typeName, out var type)) { deserializeResult += fsResult.Fail("Unable to find type: '" + typeName + "'"); break; } if (storageType.IsAssignableFrom(type) == false) { deserializeResult.AddMessage("Ignoring type specifier; a field/property of type " + storageType + " cannot hold an instance of " + type); break; } objectType = type; }while (false); } RemapAbstractStorageTypeToDefaultType(ref objectType); // We wait until here to actually Invoke_OnBeforeDeserialize because // we do not have the correct set of processors to invoke until // *after* we have resolved the proper type to use for // deserialization. processors = GetProcessors(objectType); if (deserializeResult.Failed) { return(deserializeResult); } // LAZLO / LUDIQ FIX try { Invoke_OnBeforeDeserialize(processors, storageType, ref data); } catch (Exception ex) { return(deserializeResult += fsResult.Fail(ex.ToString())); } // Construct an object instance if we don't have one already. We also // need to construct an instance if the result type is of the wrong // type, which may be the case when we have a versioned import graph. if (ReferenceEquals(result, null) || result.GetType() != objectType) { result = GetConverter(objectType, overrideConverterType).CreateInstance(data, objectType); } // We call OnBeforeDeserializeAfterInstanceCreation here because we // still want to invoke the method even if the user passed in an // existing instance. try { Invoke_OnBeforeDeserializeAfterInstanceCreation(processors, storageType, result, ref data); } catch (Exception ex) { return(deserializeResult += fsResult.Fail(ex.ToString())); } // NOTE: It is critically important that we pass the actual // objectType down instead of using result.GetType() because it // is not guaranteed that result.GetType() will equal // objectType, especially because some converters are known to // return dummy values for CreateInstance() (for example, the // default behavior for structs is to just return the type of // the struct). return(deserializeResult += InternalDeserialize_4_Cycles(overrideConverterType, data, objectType, ref result)); }