Class IniFile
Provides read/write access to a file in the INI format.
This class is not threadsafe.
public class IniFile
- Inheritance
-
IniFile
- Derived
- Inherited Members
Constructors
IniFile(string)
Construct a new IniFile.
public IniFile(string filePath)
Parameters
filePath
stringpath of the IniFile
Properties
FilePath
the path of the file
public string FilePath { get; }
Property Value
Methods
CopySection(string, string, Dictionary<string, string>)
Copy the section fromSectionName to toSectionName
public void CopySection(string fromSectionName, string toSectionName, Dictionary<string, string> replaceProperties)
Parameters
fromSectionName
stringtoSectionName
stringreplaceProperties
Dictionary<string, string>Any properties in the original section that are also in this dictionary will be replaced by the value from this dictionary.
CopySection(string, string, Dictionary<string, string>, bool)
Copy the section fromSectionName to toSectionName
public void CopySection(string fromSectionName, string toSectionName, Dictionary<string, string> replaceProperties, bool force)
Parameters
fromSectionName
stringtoSectionName
stringreplaceProperties
Dictionary<string, string>Any properties in the original section that are also in this dictionary will be replaced by the value from this dictionary.
force
boolif true and destination section already exists overwrite it
DeleteSection(string)
If the section exists, delete it from the INI file.
public void DeleteSection(string sectionName)
Parameters
sectionName
stringsection to delete
EditSection(string, SortedDictionary<string, string>)
Update the section with the properties given. If the section doesn't exist, it will be appended to the file.
Notes:
- Any properties that do exist in the section will be updated.
- A null value for a property denotes that it should be deleted from the section
- If any properties don't exist they will be appended to the end of the section in the same order they appear in the SortedDictionary.
public virtual void EditSection(string sectionName, SortedDictionary<string, string> properties)
Parameters
sectionName
stringname of the section to operate on
properties
SortedDictionary<string, string>properties to add/update/delete
EnsureSectionExists(string)
Check if the section exists. If not, append it to the end of the file.
public void EnsureSectionExists(string sectionName)
Parameters
sectionName
stringsection to ensure exists
ListSectionNames()
public virtual HashSet<string> ListSectionNames()
Returns
Persist()
Persist the changes to this INI file to disk.
public void Persist()
RenameSection(string, string)
Rename the section fromSectionName to toSectionName
public void RenameSection(string oldSectionName, string newSectionName)
Parameters
RenameSection(string, string, bool)
Rename the section fromSectionName to toSectionName
public void RenameSection(string oldSectionName, string newSectionName, bool force)
Parameters
oldSectionName
stringnewSectionName
stringforce
boolif true and destination section already exists overwrite it
SectionExists(string)
Determine if a section exists in the INI file.
public bool SectionExists(string sectionName)
Parameters
sectionName
stringname of section to look for
Returns
- bool
true if the section exists, false otherwise
SectionExists(Regex, out string)
Determine if a section exists in the INI file.
public bool SectionExists(Regex sectionNameRegex, out string sectionName)
Parameters
sectionNameRegex
RegexRegex to match name of section to look for
sectionName
stringname of section if regex matches
Returns
- bool
true if the section exists, false otherwise
ToString()
public override string ToString()
Returns
TryGetSection(string, out Dictionary<string, string>)
Return the properties for the section if it exists.
public virtual bool TryGetSection(string sectionName, out Dictionary<string, string> properties)
Parameters
sectionName
stringname of section to get
properties
Dictionary<string, string>properties contained in the section
Returns
- bool
True if the section was found, false otherwise
TryGetSection(Regex, out Dictionary<string, string>)
Return the properties for the section if it exists.
public bool TryGetSection(Regex sectionNameRegex, out Dictionary<string, string> properties)
Parameters
sectionNameRegex
RegexRegex to match name of section to get
properties
Dictionary<string, string>properties contained in the section
Returns
- bool
True if the section was found, false otherwise
TryGetSection(Regex, out string, out Dictionary<string, string>)
Return the properties for the section if it exists.
public bool TryGetSection(Regex sectionNameRegex, out string sectionName, out Dictionary<string, string> properties)
Parameters
sectionNameRegex
RegexRegex to match name of section to get
sectionName
stringname of section if regex matches
properties
Dictionary<string, string>properties contained in the section
Returns
- bool
True if the section was found, false otherwise