コード例 #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 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);
        }
コード例 #3
0
        private void Load(string _sName, SerialPort _Port, string _sPath = "")
        {
            //Set Dir.
            string sExeFolder  = System.AppDomain.CurrentDomain.BaseDirectory;
            string sFileName   = "Util\\SerialPort";
            string sSerialPath = sExeFolder + sFileName + ".ini";
            string sTitle      = "";

            if (sName == "")
            {
                sTitle = "PortID_" + iPortId.ToString();
            }
            else
            {
                sTitle = _sName;
            }

            CIniFile Ini;

            if (_sPath == "")
            {
                Ini = new CIniFile(sSerialPath);
            }
            else
            {
                Ini = new CIniFile(_sPath);
            }

            int iPortNo = 0;

            Ini.Load(sTitle, "PortNo", ref iPortNo); if (iPortNo == 0)
            {
                iPortNo = 1;
            }

            //맨처음 파일 없을때 대비.
            Ini.Save(sTitle, "PortNo   ", iPortNo);

            _Port.PortName = "Com" + iPortNo.ToString();
        }
コード例 #4
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);
        }
コード例 #5
0
        public void Load(SerialPort _Port, string _sPath = "")
        {
            //Set Dir.
            string sExeFolder  = System.AppDomain.CurrentDomain.BaseDirectory;
            string sFileName   = "Util\\SerialPort";
            string sSerialPath = sExeFolder + sFileName + ".ini";
            string sTitle      = "";

            if (sName == "")
            {
                sTitle = "PortID_" + iPortId.ToString();
            }
            else
            {
                sTitle = sName;
            }

            CIniFile Ini;

            if (_sPath == "")
            {
                Ini = new CIniFile(sSerialPath);
            }
            else
            {
                Ini = new CIniFile(_sPath);
            }

            int iPortNo;
            int iBaudRate;
            int iDataBit;
            int iParityBit;
            int iStopBit;

            Ini.Load(sTitle, "PortNo   ", out iPortNo); if (iPortNo == 0)
            {
                iPortNo = 1;
            }
            Ini.Load(sTitle, "BaudRate ", out iBaudRate); if (iBaudRate == 0)
            {
                iBaudRate = 9600;
            }
            Ini.Load(sTitle, "DataBit  ", out iDataBit); if (iDataBit < 5 || iDataBit > 8)
            {
                iDataBit = 8;
            }
            Ini.Load(sTitle, "ParityBit", out iParityBit);
            Ini.Load(sTitle, "StopBit  ", out iStopBit); if (iStopBit < 1 || iStopBit > 3)
            {
                iStopBit = 1;
            }

            //맨처음 파일 없을때 대비.
            Ini.Save(sTitle, "PortNo   ", iPortNo);
            Ini.Save(sTitle, "BaudRate ", iBaudRate);
            Ini.Save(sTitle, "DataBit  ", iDataBit);
            Ini.Save(sTitle, "ParityBit", iParityBit);
            Ini.Save(sTitle, "StopBit  ", iStopBit);

            _Port.PortName     = "Com" + iPortNo.ToString();
            _Port.BaudRate     = iBaudRate;          //9600 ,
            _Port.DataBits     = iDataBit;           //8
            _Port.Parity       = (Parity)iParityBit; //None = 0,Odd = 1,Even = 2,Mark = 3 ,Space = 4,
            _Port.StopBits     = (StopBits)iStopBit; //None = 0,One = 1,Two  = 2,OnePointFive = 3, None은 예외상황발생함..
            _Port.ReadTimeout  = (int)500;
            _Port.WriteTimeout = (int)500;
        }
コード例 #6
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);
        }