/// <summary> /// Deserializes an object from the specified stream (expecting a YAML string). /// </summary> /// <param name="stream">A YAML string from a stream.</param> /// <param name="expectedType">The expected type.</param> /// <param name="contextSettings">The context settings.</param> /// <returns>An instance of the YAML data.</returns> public object Deserialize(Stream stream, Type expectedType = null, SerializerContextSettings contextSettings = null) { bool aliasOccurred; PropertyContainer contextProperties; return(Deserialize(stream, expectedType, contextSettings, out aliasOccurred, out contextProperties)); }
/// <summary> /// Deserializes an object from the specified stream (expecting a YAML string). /// </summary> /// <param name="stream">A YAML string from a stream .</param> /// <param name="expectedType">The expected type.</param> /// <param name="contextSettings">The context settings.</param> /// <param name="aliasOccurred">if set to <c>true</c> a class/field/property/enum name has been renamed during deserialization.</param> /// <returns>An instance of the YAML data.</returns> public static object Deserialize(Stream stream, Type expectedType, SerializerContextSettings contextSettings, out bool aliasOccurred) { var serializer = GetYamlSerializer(); SerializerContext context; var result = serializer.Deserialize(stream, expectedType, contextSettings, out context); aliasOccurred = context.HasRemapOccurred; return(result); }
/// <summary> /// Deserializes an object from the specified stream (expecting a YAML string). /// </summary> /// <param name="stream">A YAML string from a stream .</param> /// <param name="expectedType">The expected type.</param> /// <param name="contextSettings">The context settings.</param> /// <param name="aliasOccurred">if set to <c>true</c> a class/field/property/enum name has been renamed during deserialization.</param> /// <param name="contextProperties">A dictionary or properties that were generated during deserialization.</param> /// <returns>An instance of the YAML data.</returns> public object Deserialize(Stream stream, Type expectedType, SerializerContextSettings contextSettings, out bool aliasOccurred, out PropertyContainer contextProperties) { EnsureYamlSerializer(); SerializerContext context; var result = serializer.Deserialize(stream, expectedType, contextSettings, out context); aliasOccurred = context.HasRemapOccurred; contextProperties = context.Properties; return(result); }
public void Save(Stream stream, object asset, ILogger log = null, Dictionary <YamlAssetPath, OverrideType> overrides = null) { var settings = new SerializerContextSettings(log); if (overrides != null) { settings.Properties.Add(AssetObjectSerializerBackend.OverrideDictionaryKey, overrides); } AssetYamlSerializer.Default.Serialize(stream, asset, null, settings); }
/// <summary> /// Serializes an object to a string in YAML format. /// </summary> /// <param name="instance">The instance.</param> /// <param name="type">The expected type.</param> /// <param name="contextSettings">The context settings.</param> /// <param name="generateIds"><c>true</c> to generate ~Id for class objects</param> /// <returns>a string in YAML format</returns> public static string Serialize(object instance, Type type, SerializerContextSettings contextSettings, bool generateIds = true) { var serializer = GetYamlSerializer(generateIds); using (var stream = new MemoryStream()) { serializer.Serialize(stream, instance, type ?? typeof(object), contextSettings); stream.Flush(); stream.Position = 0; return(new StreamReader(stream).ReadToEnd()); } }
public void Save(Stream stream, object asset, AttachedYamlAssetMetadata yamlMetadata, ILogger log = null) { var settings = new SerializerContextSettings(log); var overrides = yamlMetadata?.RetrieveMetadata(AssetObjectSerializerBackend.OverrideDictionaryKey); if (overrides != null) { settings.Properties.Add(AssetObjectSerializerBackend.OverrideDictionaryKey, overrides); } var objectReferences = yamlMetadata?.RetrieveMetadata(AssetObjectSerializerBackend.ObjectReferencesKey); if (objectReferences != null) { settings.Properties.Add(AssetObjectSerializerBackend.ObjectReferencesKey, objectReferences); } AssetYamlSerializer.Default.Serialize(stream, asset, null, settings); }
private static List <ParsingEvent> SerializeComponent(EntityComponent component) { // Wrap component in a EntityComponentCollection to properly handle errors var components = new Entity { component }.Components; // Serialize with Yaml layer var parsingEvents = new List <ParsingEvent>(); // We also want to serialize live component variables var serializerContextSettings = new SerializerContextSettings { MemberMask = DataMemberAttribute.DefaultMask | ScriptComponent.LiveScriptingMask }; AssetYamlSerializer.Default.Serialize(new ParsingEventListEmitter(parsingEvents), components, typeof(EntityComponentCollection), serializerContextSettings); return(parsingEvents); }
protected override List <ParsingEvent> SerializeScript(Script script) { // Wrap script in a ScriptCollection to properly handle errors var scriptCollection = new ScriptCollection { script }; // Serialize with Yaml layer var parsingEvents = new List <ParsingEvent>(); // We also want to serialize live scripting variables var serializerContextSettings = new SerializerContextSettings { MemberMask = DataMemberAttribute.DefaultMask | Script.LiveScriptingMask }; YamlSerializer.Serialize(new ParsingEventListEmitter(parsingEvents), scriptCollection, typeof(ScriptCollection), serializerContextSettings); return(parsingEvents); }
protected override bool ProcessObject(object obj, Type expectedType) { // TODO: More advanced checks if IUnloadable is supposed to be a type from the unloaded assembly (this would avoid processing unecessary IUnloadable) if (obj != null && (UnloadedAssemblies.Contains(obj.GetType().Assembly) || obj is IUnloadable)) { NodeIndex index; var settings = new SerializerContextSettings(Log); var path = GraphNodePath.From(propertyGraph.RootNode, CurrentPath, out index); var overrides = AssetPropertyGraph.GenerateOverridesForSerialization(path.GetNode()); overrides = RemoveFirstIndexInYamlPath(overrides, index); if (overrides != null) { settings.Properties.Add(AssetObjectSerializerBackend.OverrideDictionaryKey, overrides); } var objectReferences = propertyGraph.GenerateObjectReferencesForSerialization(path.GetNode()); objectReferences = RemoveFirstIndexInYamlPath(objectReferences, index); if (objectReferences != null) { settings.Properties.Add(AssetObjectSerializerBackend.ObjectReferencesKey, objectReferences); } var parsingEvents = new List <ParsingEvent>(); AssetYamlSerializer.Default.Serialize(new ParsingEventListEmitter(parsingEvents), obj, expectedType, settings); // Buid parent path var parentPath = CurrentPath.Clone(); parentPath.Pop(); ItemsToReload.Add(new ItemToReload(parentPath, CurrentPath.Clone(), parsingEvents, expectedType)); // Don't recurse inside return(true); } return(false); }
/// <summary> /// Deserializes an object from the specified stream (expecting a YAML string). /// </summary> /// <param name="stream">A YAML string from a stream.</param> /// <param name="expectedType">The expected type.</param> /// <param name="contextSettings">The context settings.</param> /// <returns>An instance of the YAML data.</returns> public static object Deserialize(Stream stream, Type expectedType, SerializerContextSettings contextSettings) { var serializer = GetYamlSerializer(); return(serializer.Deserialize(stream, expectedType, contextSettings)); }
/// <summary> /// Serializes an object to specified stream in YAML format. /// </summary> /// <param name="emitter">The emitter.</param> /// <param name="instance">The object to serialize.</param> /// <param name="type">The type.</param> /// <param name="contextSettings">The context settings.</param> public void Serialize(IEmitter emitter, object instance, Type type, SerializerContextSettings contextSettings = null) { EnsureYamlSerializer(); serializer.Serialize(emitter, instance, type, contextSettings); }
/// <summary> /// Serializes an object to specified stream in YAML format. /// </summary> /// <param name="stream">The stream to receive the YAML representation of the object.</param> /// <param name="instance">The instance.</param> /// <param name="type">The expected type.</param> /// <param name="contextSettings">The context settings.</param> /// <param name="generateIds"><c>true</c> to generate ~Id for class objects</param> public static void Serialize(Stream stream, object instance, Type type, SerializerContextSettings contextSettings, bool generateIds = true) { var serializer = GetYamlSerializer(); serializer.Serialize(stream, instance, type, contextSettings); }
/// <summary> /// Serializes an object to specified stream in YAML format. /// </summary> /// <param name="emitter">The emitter.</param> /// <param name="instance">The object to serialize.</param> /// <param name="type">The type.</param> /// <param name="contextSettings">The context settings.</param> public static void Serialize(IEmitter emitter, object instance, Type type, SerializerContextSettings contextSettings) { var serializer = GetYamlSerializer(); serializer.Serialize(emitter, instance, type, contextSettings); }
/// <summary> /// Deserializes an object from the specified stream (expecting a YAML string). /// </summary> /// <param name="eventReader">A YAML event reader.</param> /// <param name="value">The value.</param> /// <param name="expectedType">The expected type.</param> /// <param name="contextSettings">The context settings.</param> /// <returns>An instance of the YAML data.</returns> public static object Deserialize(EventReader eventReader, object value, Type expectedType, SerializerContextSettings contextSettings) { var serializer = GetYamlSerializer(); return(serializer.Deserialize(eventReader, expectedType, value, contextSettings)); }
/// <summary> /// Serializes an object to specified stream in YAML format. /// </summary> /// <param name="stream">The stream to receive the YAML representation of the object.</param> /// <param name="instance">The instance.</param> /// <param name="type">The expected type.</param> /// <param name="contextSettings">The context settings.</param> public void Serialize(Stream stream, object instance, Type type = null, SerializerContextSettings contextSettings = null) { EnsureYamlSerializer(); serializer.Serialize(stream, instance, type, contextSettings); }
/// <summary> /// Serializes an object to specified stream in YAML format. /// </summary> /// <param name="stream">The stream to receive the YAML representation of the object.</param> /// <param name="instance">The instance.</param> /// <param name="type">The type.</param> /// <param name="contextSettings">The context settings.</param> /// <param name="keepOnlySealedOverrides">if set to <c>true</c> [keep only sealed overrides].</param> public static void Serialize(Stream stream, object instance, Type type, SerializerContextSettings contextSettings, bool keepOnlySealedOverrides = false) { var serializer = GetYamlSerializer(keepOnlySealedOverrides); serializer.Serialize(stream, instance, type, contextSettings); }
/// <summary> /// Deserializes an object from the specified stream (expecting a YAML string). /// </summary> /// <param name="eventReader">A YAML event reader.</param> /// <param name="value">The value.</param> /// <param name="expectedType">The expected type.</param> /// <param name="contextProperties">A dictionary or properties that were generated during deserialization.</param> /// <param name="contextSettings">The context settings.</param> /// <returns>An instance of the YAML data.</returns> public object Deserialize(EventReader eventReader, object value, Type expectedType, out PropertyContainer contextProperties, SerializerContextSettings contextSettings = null) { EnsureYamlSerializer(); SerializerContext context; var result = serializer.Deserialize(eventReader, expectedType, value, contextSettings, out context); contextProperties = context.Properties; return(result); }