Пример #1
0
        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 }));
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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));
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        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);
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        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));
        }
Пример #9
0
            internal void ReadLine(string line, INIFile src)
            {
                INILine newiniline = INILine.ReadLine(line, src);

                m_lines.Add(newiniline);
            }