internal object Read(Type t, INIFile f, string fieldName, string defaultSection, IResolver resolver) { if (!t.IsArray || t.GetElementType().IsArray) { throw new InvalidOperationException(Resource.Strings.Error_INISubSectionKeyListInvalidType.F(t.Name)); } string s = INIAttributeExt.GetSection(Section, defaultSection ?? fieldName); INIKeyListAttribute kattr = new INIKeyListAttribute(s, ValueSource, Required); string[] subsections = kattr.Read(typeof(string[]), f, s); MethodInfo mRead = GetType().GetMethod(nameof(InnerRead), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo gmRead = mRead.MakeGenericMethod(t.GetElementType()); return(gmRead.Invoke(this, new object[] { f, subsections, resolver })); }
/// <summary>Reads and parses the INI file from a source file</summary> public void ReadFromFile(string filepath, string baseSection = null, IResolver resolver = null) { if (!File.Exists(filepath)) { throw new FileNotFoundException(Resource.Strings.Error_FileNotFound.F(Path.GetFullPath(filepath))); } else { Reset(); using (StreamReader sr = new StreamReader(filepath)) Read(sr); } INIFile t = this; LoadByAttribute(ref t, baseSection, resolver); }
private void InnerWrite <T>(INIFile f, T[] value, string fieldName, string defaultSection) { if (value == default) { return; } string s = INIAttributeExt.GetSection(Section, defaultSection); string k = SubsectionPrefix ?? INIAttributeExt.GetKey(Key, fieldName); string[] keys = new string[value.Length]; for (int i = 0; i < value.Length; i++) { T o = value[i]; keys[i] = fieldName + i.ToString(); f.UpdateByAttribute(ref o, keys[i]); } f.SetValue(s, k, Parser.Write(keys)); }
private void InnerWrite <T, U>(INIFile f, Registry <T, U> reg, string defaultSection) { if (reg == default) { return; } string s = INIAttributeExt.GetSection(Section, defaultSection); foreach (T t in reg.GetKeys()) { string key = Parser.Write(t); string value = Parser.Write(reg.Get(t)); if (value != (string)NoWriteValue) { f.SetString(s, key, value); } } }
internal void Write(Type t, INIFile f, string[] value, string defaultSection) { if (value == null) { return; } if (t != typeof(string[])) { throw new InvalidOperationException(Resource.Strings.Error_INIKeyListInvalidType.F(t.Name)); } string s = INIAttributeExt.GetSection(Section, defaultSection); int count = 0; foreach (string v in value) { SetValue(ValueSource, f, count++, s, v); } }
private void InnerWrite <T, U>(INIFile f, Registry <T, U> registry, string fieldName, string defaultSection) { if (registry == default) { return; } string s = INIAttributeExt.GetSection(Section, defaultSection ?? fieldName); //string k = SubsectionPrefix ?? fieldName; //Registry<string, string> keylinks = new Registry<string, string>(); foreach (T key in registry.GetKeys()) { string skey = Parser.Write(key); U o = registry[key]; string vkey = "{0}{1}".F(fieldName, skey); f.UpdateByAttribute(ref o, vkey); f.SetValue(s, skey, vkey); } }
private Registry <T, U> InnerRead <T, U>(INIFile f, string defaultSection, IResolver resolver) { string s = INIAttributeExt.GetSection(Section, defaultSection); Registry <T, U> ret = new Registry <T, U>(); if (f.HasSection(s)) { foreach (INIFile.INISection.INILine ln in f.GetSection(s).Lines) { if (ln.HasKey) { ret.Add(Parser.Parse(ln.Key, default(T)), Parser.Parse(ln.Value, resolver, default(U))); } } } else if (Required) { throw new INISectionNotFoundException(s); } return(ret); }
private void InnerWrite <T>(INIFile f, T[] value, string fieldName, string defaultSection) { if (value == default) { return; } string s = INIAttributeExt.GetSection(Section, defaultSection ?? fieldName); string[] keys = new string[value.Length]; for (int i = 0; i < value.Length; i++) { T o = value[i]; keys[i] = fieldName + i.ToString(); f.UpdateByAttribute(ref o, keys[i]); } INIKeyListAttribute kattr = new INIKeyListAttribute(s, ValueSource, Required); kattr.Write(typeof(string[]), f, keys, s); //f.SetValue(s, k, Parser.Write(keys)); }
internal void ReadLine(string line, INIFile src) { INILine newiniline = INILine.ReadLine(line, src); m_lines.Add(newiniline); }