internal string[] Read(Type t, INIFile f, string defaultSection) { if (t != typeof(string[])) { throw new InvalidOperationException(Resource.Strings.Error_INIKeyListInvalidType.F(t.Name)); } string s = INIAttributeExt.GetSection(Section, defaultSection); List <string> vals = new List <string>(); if (f.HasSection(s)) { foreach (INIFile.INISection.INILine ln in f.GetSection(s).Lines) { if (ln.HasKey) { vals.Add(GetValue(ValueSource, ln.Key, ln.Value)); } } } else if (Required) { throw new INISectionNotFoundException(s); } return(vals.ToArray()); }
private T InnerRead <T>(INIFile f, T defaultValue, string fieldName, string defaultSection, IResolver resolver) { string s = INIAttributeExt.GetSection(Section, defaultSection); string k = INIAttributeExt.GetKey(Key, fieldName); if (Required && !f.HasKey(s, k)) { throw new INIKeyNotFoundException(s, k); } return(Parser.Parse(f.GetString(s, k, null), resolver, defaultValue)); }
private T[] InnerRead <T>(INIFile f, string fieldName, string defaultSection, IResolver resolver) { string s = INIAttributeExt.GetSection(Section, defaultSection); string k = INIAttributeExt.GetKey(Key, fieldName); string[] list = f.GetValue(s, k, resolver, new string[0]); T[] ret = new T[list.Length]; for (int i = 0; i < list.Length; i++) { T instance = Activator.CreateInstance <T>(); f.LoadByAttribute(ref instance, list[i], resolver); ret[i] = instance; } return(ret); }
private void InnerWrite <T>(INIFile f, T value, string fieldName, string defaultSection) { if (typeof(T).IsClass && value == null) { return; } string s = INIAttributeExt.GetSection(Section, defaultSection); string k = INIAttributeExt.GetKey(Key, fieldName); string v = Parser.Write(value); if (!v.Equals(NoWriteValue)) { f.SetString(s, k, v); } }
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 })); }
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)); }