public static string ToYAML(object objectToSerialize) { string retVal = null; using (MemoryStream memStream = new MemoryStream()) { using (var streamWriter = new StreamWriter(memStream)) { _yamlSerializer.Serialize(streamWriter, objectToSerialize); streamWriter.Flush(); // Convert stream to string memStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(memStream); retVal = reader.ReadToEnd(); } } return(retVal); }
public static string ToYaml(object model, YamlDotNet.Serialization.ISerializer serializer) { string yaml; using (var memStream = new MemoryStream()) { using (var streamWriter = new StreamWriter(memStream)) { serializer.Serialize(streamWriter, model); streamWriter.Flush(); // Convert stream to string memStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(memStream); yaml = reader.ReadToEnd(); } } return(yaml); }