/// <summary> /// Write a key-value collection to a file. /// </summary> /// <param name="map">The collection to be written to the file in YAML format.</param> /// <param name="filename">Filename of a MicroYaml document.</param> /// <param name="includeDocumentMarkers">If true, includes the document start marker "---" and document end marker. "...".</param> /// <param name="append">If true, appends the output to the end of the file. Otherwise overwrites.</param> /// <returns>The number of key-value pairs written to the file.</returns> static public int Save <TKey, TValue>(IEnumerable <KeyValuePair <TKey, TValue> > map, string filename, bool includeDocumentMarkers = true, bool append = false) { using (var yamlWriter = new MicroYamlWriter(filename, includeDocumentMarkers, append)) { return(yamlWriter.Write(map)); } }
/// <summary> /// Write a key-value collection to a stream. /// </summary> /// <param name="map">The collection to be written to the stream in YAML format.</param> /// <param name="stream">Stream to which the YAML should be written.</param> /// <param name="includeDocumentMarkers">If true, includes the document start marker "---" and document end marker. "...".</param> /// <returns>The number of key-value pairs written to the stream.</returns> static public int Save <TKey, TValue>(IEnumerable <KeyValuePair <TKey, TValue> > map, Stream stream, bool includeDocumentMarkers = true) { using (var yamlWriter = new MicroYamlWriter(stream, includeDocumentMarkers, true)) { return(yamlWriter.Write(map)); } }
/// <summary> /// Write a key-value collection to a string in YAML format. /// </summary> /// <param name="map">The collection to be written to the string in YAML format.</param> /// <param name="includeDocumentMarkers">If true, includes the document start marker "---" and document end marker. "...".</param> /// <returns>A string containing the YAML content.</returns> static public string SaveToString <TKey, TValue>(IEnumerable <KeyValuePair <TKey, TValue> > map, bool includeDocumentMarkers = true) { using (var sw = new StringWriter()) { using (var yamlWriter = new MicroYamlWriter(sw, includeDocumentMarkers)) { yamlWriter.Write(map); } return(sw.ToString()); } }