예제 #1
0
        public static bool LoadStruct <T>(string _sFilePath, string _sSection, ref T _oStruct)
        {
            CIniFile Ini = new CIniFile(_sFilePath);

            Type type = _oStruct.GetType();

            string sKey;
            string sValue;

            FieldInfo[] f = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            for (int i = 0; i < f.Length; i++)
            {
                sKey = f[i].Name;
                Ini.Load(_sSection, sKey, out sValue);
                if (f[i].FieldType == typeof(bool))
                {
                    f[i].SetValueDirect(__makeref(_oStruct), CIniFile.StrToBoolDef(sValue, false));
                }
                else if (f[i].FieldType == typeof(int))
                {
                    f[i].SetValueDirect(__makeref(_oStruct), CIniFile.StrToIntDef(sValue, 0));
                }
                else if (f[i].FieldType == typeof(double))
                {
                    f[i].SetValueDirect(__makeref(_oStruct), CIniFile.StrToDoubleDef(sValue, 0.0));
                }
                else if (f[i].FieldType == typeof(string))
                {
                    f[i].SetValueDirect(__makeref(_oStruct), sValue);
                }
            }
            return(true);
        }
예제 #2
0
파일: CIniFile.cs 프로젝트: zoro-008/Works
        public static bool LoadStruct <T>(string _sFilePath, string _sSection, ref T _oStruct)
        {
            CIniFile Ini = new CIniFile(_sFilePath);

            Type type = _oStruct.GetType();

            string sKey;
            string sValue = "";
            int    iValue = 0;
            bool   bValue = false;
            double dValue = 0;
            Type   tType;

            BindingFlags Flags = BindingFlags.Public |
                                 BindingFlags.NonPublic |
                                 BindingFlags.Instance;

            FieldInfo[] f = type.GetFields(Flags);
            for (int i = 0; i < f.Length; i++)
            {
                sKey  = f[i].Name;
                tType = f[i].FieldType;

                if (tType == typeof(bool))
                {
                    Ini.Load(_sSection, sKey, ref bValue); f[i].SetValueDirect(__makeref(_oStruct), bValue);
                }
                else if (tType == typeof(int))
                {
                    Ini.Load(_sSection, sKey, ref iValue); f[i].SetValueDirect(__makeref(_oStruct), iValue);
                }
                else if (tType == typeof(double))
                {
                    Ini.Load(_sSection, sKey, ref dValue); f[i].SetValueDirect(__makeref(_oStruct), dValue);
                }
                else if (tType == typeof(string))
                {
                    Ini.Load(_sSection, sKey, ref sValue); f[i].SetValueDirect(__makeref(_oStruct), sValue);
                }

                else if (tType == typeof(bool[]))
                {
                    bool [] Values = (bool[])f[i].GetValue(_oStruct);
                    Ini.Load(_sSection, sKey, ref Values); f[i].SetValueDirect(__makeref(_oStruct), Values);
                }
                else if (tType == typeof(int[]))
                {
                    int [] Values = (int[])f[i].GetValue(_oStruct);
                    Ini.Load(_sSection, sKey, ref Values); f[i].SetValueDirect(__makeref(_oStruct), Values);
                }
                else if (tType == typeof(double[]))
                {
                    double [] Values = (double[])f[i].GetValue(_oStruct);
                    Ini.Load(_sSection, sKey, ref Values); f[i].SetValueDirect(__makeref(_oStruct), Values);
                }
                else if (tType == typeof(string[]))
                {
                    string [] Values = (string[])f[i].GetValue(_oStruct);//new string [tType.GetFields(Flags).Length];
                    Ini.Load(_sSection, sKey, ref Values); f[i].SetValueDirect(__makeref(_oStruct), Values);
                }
            }
            return(true);
        }