Пример #1
0
        static T InitT <T>(string file) where T : AppInfo, new()
        {
            T       insEntity = new T();
            ReadINI r         = new ReadINI();
            Dictionary <string, string> dicConfig = r.Read(file);
            Type type = typeof(T);

            System.Reflection.PropertyInfo[] proinfo = type.GetProperties(System.Reflection.BindingFlags.Instance
                                                                          | System.Reflection.BindingFlags.Public
                                                                          );
            foreach (System.Reflection.PropertyInfo pItem in proinfo)
            {
                if (!dicConfig.ContainsKey(pItem.Name))
                {
                    continue;
                }
                object dynmicValue = System.ComponentModel.TypeDescriptor.GetConverter(pItem.PropertyType).ConvertFromString(dicConfig[pItem.Name]);//创建对象
                pItem.SetValue(insEntity, dynmicValue);
            }
            return(insEntity);
        }
Пример #2
0
        void init()
        {
            ReadINI r = new ReadINI();

            DicValues = r.Read(fileConfig);
        }