NSoft.NFramework.Nini.Ini.IniSection.Set C# (CSharp) Method

Set() public method

public Set ( string key, string value, string comment = null ) : void
key string
value string
comment string
return void
        public void Set(string key, string value, string comment = null) {
            IniItem item = null;

            if(Contains(key)) {
                item = (IniItem)configList[key];
                item.Value = value;
                item.Comment = comment;
            }
            else {
                item = new IniItem(key, value, IniType.Key, comment);
                configList.Add(key, item);
            }
        }

Same methods

IniSection::Set ( ) : void
IniSection::Set ( string comment ) : void

Usage Example

示例#1
0
        public void SaveAsMysqlStyle()
        {
            string     filePath = "Save.ini";
            FileStream stream   = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();

            doc.FileType = IniFileType.MysqlStyle;
            IniSection section = new IniSection("Pets");

            section.Set("my comment");
            section.Set("dog", "rover");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            StringWriter writer = new StringWriter();

            writer.WriteLine("[Pets]");
            writer.WriteLine("# my comment");
            writer.WriteLine("dog = rover");

            StreamReader reader = new StreamReader(filePath);

            Assert.AreEqual(writer.ToString(), reader.ReadToEnd());
            reader.Close();

            IniDocument iniDoc = new IniDocument();

            iniDoc.FileType = IniFileType.MysqlStyle;
            iniDoc.Load(filePath);

            File.Delete(filePath);
        }
All Usage Examples Of NSoft.NFramework.Nini.Ini.IniSection::Set