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

            Type type = _oStruct.GetType();

            string sKey;
            string sValue;
            bool   bRet = true;
            Type   tType;

            FieldInfo[] f = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            for (int i = 0; i < f.Length; i++)
            {
                sKey  = f[i].Name;
                tType = f[i].FieldType;
                //sValue = ;
                //if(!Ini.Save(_sSection , sKey , sValue)) bRet = false ;

                if (tType == typeof(bool))
                {
                    Ini.Save(_sSection, sKey, f[i].GetValue(_oStruct).ToString());
                }
                else if (tType == typeof(int))
                {
                    Ini.Save(_sSection, sKey, f[i].GetValue(_oStruct).ToString());
                }
                else if (tType == typeof(double))
                {
                    Ini.Save(_sSection, sKey, f[i].GetValue(_oStruct).ToString());
                }
                else if (tType == typeof(string))
                {
                    Ini.Save(_sSection, sKey, f[i].GetValue(_oStruct).ToString());
                }
                else if (tType == typeof(bool[]))
                {
                    bool [] Values = (bool[])f[i].GetValue(_oStruct);
                    Ini.Save(_sSection, sKey, Values);
                }
                else if (tType == typeof(int[]))
                {
                    int [] Values = (int[])f[i].GetValue(_oStruct);
                    Ini.Save(_sSection, sKey, Values);
                }
                else if (tType == typeof(double[]))
                {
                    double [] Values = (double[])f[i].GetValue(_oStruct);
                    Ini.Save(_sSection, sKey, Values);
                }
                else if (tType == typeof(string[]))
                {
                    string [] Values = (string[])f[i].GetValue(_oStruct);//new string [tType.GetFields(Flags).Length];
                    Ini.Save(_sSection, sKey, Values);
                }
            }

            return(bRet);
        }
Beispiel #2
0
        public static bool SaveStruct <T>(string _sFilePath, string _sSection, ref T _oStruct)
        {
            CIniFile Ini = new CIniFile(_sFilePath);

            Type type = _oStruct.GetType();

            string sKey;
            string sValue;
            bool   bRet = true;

            FieldInfo[] f = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            for (int i = 0; i < f.Length; i++)
            {
                sKey   = f[i].Name;
                sValue = f[i].GetValue(_oStruct).ToString();
                if (!Ini.Save(_sSection, sKey, sValue))
                {
                    bRet = false;
                }
            }

            return(bRet);
        }