Skip to content

yangzheng006/IniFile

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

IniFile

IniFile is a single C# file that offers reading from and writing to INI files. You can drop it straight into your project; no DLL references needed.

Basic usage

Reading an INI file

// [foo]
// bar=1
// baz=qux
// [foo2]
// bar=2
		
var iniFile = new IniFile("foo.ini");
iniFile.Section("foo").Get("bar"); // "1"
iniFile.Section("foo").Get("baz"); // "qux"
		
foreach (var section in iniFile.Sections)
	Console.WriteLine(section.Name); // foo
								     // foo2

Writing an INI file

var iniFile = new IniFile();
	
iniFile.Section("foo").Comment = "This is foo";
iniFile.Section("foo").Set("bar", "1");
iniFile.Section("foo").Set("baz", "qux", comment: "baz is qux");

iniFile.Section("foo2").Set("bar", "2");

iniFile.Save("foo.ini");

// # This is foo
// [foo]
// bar=1
// # baz is qux
// baz=qux
//
// [foo2]
// bar=2

iniFile.Section("foo").RemoveProperty("bar"); // or iniFile.Section("foo").Set("bar", null);
iniFile.RemoveSection("foo2");
iniFile.Save("foo.ini");

// # This is foo
// [foo]
// # baz is qux
// baz=qux

About

Read and write INI files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%