public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar) { Guid identifier; if (!TryParse(fromScalar.Value, out identifier)) { throw new YamlException($"Unable to deserialize reference: [{fromScalar.Value}]"); } // Add the path to the currently deserialized object to the list of object references YamlAssetMetadata <Guid> objectReferences; if (!context.SerializerContext.Properties.TryGetValue(AssetObjectSerializerBackend.ObjectReferencesKey, out objectReferences)) { objectReferences = new YamlAssetMetadata <Guid>(); context.SerializerContext.Properties.Add(AssetObjectSerializerBackend.ObjectReferencesKey, objectReferences); } var path = AssetObjectSerializerBackend.GetCurrentPath(ref context, true); objectReferences.Set(path, identifier); // Return default(T) //return !context.Descriptor.Type.IsValueType ? null : Activator.CreateInstance(context.Descriptor.Type); // Return temporary proxy instance var proxy = (IIdentifiable)AbstractObjectInstantiator.CreateConcreteInstance(context.Descriptor.Type); proxy.Id = identifier; return(proxy); }
private static bool ShouldSerializeAsScalar(ref ObjectContext objectContext) { YamlAssetMetadata<Guid> objectReferences; if (!objectContext.SerializerContext.Properties.TryGetValue(AssetObjectSerializerBackend.ObjectReferencesKey, out objectReferences)) return false; var path = AssetObjectSerializerBackend.GetCurrentPath(ref objectContext, true); return objectReferences.TryGet(path) != Guid.Empty; }