/// <summary> /// Writes settings to a file, given a streamwriter. /// </summary> /// <param name="type">The settings.</param> /// <param name="writer">The streamwriter.</param> public void WriteFile(TempSettings type, StreamWriter writer) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } FileIniDataParser parser = new FileIniDataParser(); IniData data = new IniData(); // Weight values for Descriptors foreach ((string name, double value) in type.Weights) { data[nameof(type.Weights)][name] = value.ToString(Settings.Culture); } // Variables and counts in Settings foreach ((string name, int value) in type.Variables) { data[nameof(type.Variables)][name] = value.ToString(Settings.Culture); } // Weight values for Descriptors foreach ((string name, bool value) in type.Flow) { data[nameof(type.Flow)][name] = value.ToString(Settings.Culture); } parser.WriteData(writer, data); }
public static string WriteConfig(IniParser.Model.IniData data) { var parser = new FileIniDataParser(new IniDataParser(new IniParser.Model.Configuration.IniParserConfiguration { CommentString = "#" })); var stream = new MemoryStream(); parser.WriteData(new StreamWriter(stream), data); stream.Position = 0; return(new StreamReader(stream).ReadToEnd()); }