Пример #1
0
        public static void Save <T>(T config, string configFileName = "config.ini") where T : new()
        {
            STA.Settings.INIFile ini = GetINI(configFileName);
            var t     = typeof(T);
            var props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var p in props)
            {
                var method = ini.GetType().GetMethod("SetValue", new Type[] { typeof(string), typeof(string), p.PropertyType });
                method.Invoke(ini, new object[] { "", p.Name, p.GetValue(config, null) });
            }
        }
Пример #2
0
        public static T Load <T>(string configFileName = "config.ini") where T : new()
        {
            STA.Settings.INIFile ini = GetINI(configFileName);
            var t      = typeof(T);
            var props  = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var config = new T();

            foreach (var p in props)
            {
                var method = ini.GetType().GetMethod("GetValue", new Type[] { typeof(string), typeof(string), p.PropertyType });
                p.SetValue(config, method.Invoke(ini, new object[] { "", p.Name, GetDefaultValue(p.PropertyType) }), null);
            }
            return(config);
        }