-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Situation: save a base section as a template, containing some common k-v pairs, and to allow additional k-v pairs append on it
First, read an IniSection from template.ini file:
[Template]
foo=barvar templateIni = new IniFile("template.ini");
var templateSection = templateIni.GetSection("Template");Then, append this section to instance.ini file with a modified section name:
var instanceIni = new IniFile();
// need to clone the IniSection to prevent `templateSection` be modified
instanceSection = templateSection.Clone("new section name"); // or should the section name be settable?
instanceSection.AddKey("foo", "bar");
instanceIni.AddSection(instanceSection);
instanceIni.WriteIniFile("instance.ini");Due to missing Clone() method, I have to use the following codes instead
IniSection newSection = new("new section name");
foreach (var kvp in oldSection.Keys)
{
newSection.AddKey(kvp.Key, kvp.Value);
}But this exposes Keys and more importantly, assumes that only section name and Keys variables are all elements of an IniSection. So this code is not robust against library upgrades.
So should be better to provide a Clone() method or a constructor accepting a section name with an existing IniSection as a parameter?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels