예제 #1
0
        private bool LoadObj(CConfig _cConfig, object _oObj)
        {
            Type ObjType = _oObj.GetType();// this.GetType();//.GetType();

            //PropertyInfo[] ObjPropInfo = ObjType.GetProperties();
            FieldInfo[] ObjFieldInfo = ObjType.GetFields();

            string sMemName;
            string sMemType;
            Type   MemType;

            string sValue;
            int    iTemp;
            double dTemp;
            string sTemp;
            bool   bTemp;

            foreach (FieldInfo MemInfo in ObjFieldInfo)
            {
                sMemName = MemInfo.Name;
                sMemType = MemInfo.FieldType.FullName;
                MemType  = MemInfo.FieldType;



                if (MemType == typeof(int))
                {
                    _cConfig.GetValue(ObjType.Name, sMemName, out sValue);
                    //struct는 콜바잉벨류라 박싱 언박싱을 해줘서 콜바이 레퍼런스로 교체.
                    iTemp = CConfig.StrToIntDef(sValue, 0);
                    MemInfo.SetValue(_oObj, iTemp);
                    Log.Trace(sMemName, sValue);
                }
                else if (MemType == typeof(bool))
                {
                    _cConfig.GetValue(ObjType.Name, sMemName, out sValue);
                    bTemp = CConfig.StrToBoolDef(sValue, false);
                    MemInfo.SetValue(_oObj, bTemp);
                    Log.Trace(sMemName, sValue);
                }
                else if (MemType == typeof(double))
                {
                    _cConfig.GetValue(ObjType.Name, sMemName, out sValue);
                    dTemp = CConfig.StrToDoubleDef(sValue, 0.0);
                    MemInfo.SetValue(_oObj, dTemp);
                    Log.Trace(sMemName, sValue);
                }
                else if (MemType == typeof(string))
                {
                    _cConfig.GetValue(ObjType.Name, sMemName, out sValue);
                    sTemp = sValue;
                    MemInfo.SetValue(_oObj, sTemp);
                    Log.Trace(sMemName, sValue);
                }
                else if (MemType == typeof(int[]))
                {
                    int[] iAray = (int[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < iAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.GetValue(ObjType.Name, sIndex, out sValue);
                        iTemp    = CConfig.StrToIntDef(sValue, 0);
                        iAray[i] = iTemp;

                        Log.Trace(sIndex, iAray[i].ToString());
                    }
                }
                else if (MemType == typeof(bool[]))
                {
                    bool[] bAray = (bool[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < bAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.GetValue(ObjType.Name, sIndex, out sValue);
                        bTemp    = CConfig.StrToBoolDef(sValue, false);
                        bAray[i] = bTemp;

                        Log.Trace(sIndex, bAray[i].ToString());
                    }
                }
                else if (MemType == typeof(double[]))
                {
                    double[] dAray = (double[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < dAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.GetValue(ObjType.Name, sIndex, out sValue);
                        dTemp    = CConfig.StrToDoubleDef(sValue, 0);
                        dAray[i] = dTemp;

                        Log.Trace(sIndex, dAray[i].ToString());
                    }
                }
                else if (MemType == typeof(string[]))
                {
                    string[] sAray = (string[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < sAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.GetValue(ObjType.Name, sIndex, out sValue);
                        //MemInfo.SetValue(_oObj,sValue);
                        sAray[i] = sValue;

                        Log.Trace(sIndex, sAray[i].ToString());
                    }
                }
            }


            return(true);
        }
예제 #2
0
        private bool SaveObj(CConfig _cConfig, object _oObj)
        {
            Type ObjType = _oObj.GetType();

            FieldInfo[] ObjFieldInfo = ObjType.GetFields();

            string sMemName;
            string sMemType;
            Type   MemType;
            object oTemp;

            string sValue = string.Empty;

            foreach (FieldInfo MemInfo in ObjFieldInfo)
            {
                sMemName = MemInfo.Name;
                sMemType = MemInfo.FieldType.FullName;
                MemType  = MemInfo.FieldType;

                if (MemType == typeof(int) ||
                    MemType == typeof(bool) ||
                    MemType == typeof(double) ||
                    MemType == typeof(string))
                {
                    oTemp = MemInfo.GetValue(_oObj);

                    if (oTemp != null)
                    {
                        sValue = MemInfo.GetValue(_oObj).ToString();
                    }
                    else
                    {
                        sValue = "";
                    }

                    _cConfig.SetValue(ObjType.Name, sMemName, sValue);
                    Log.Trace(sMemName, sValue);
                }
                else if (MemType == typeof(int[]))
                {
                    int[] iAray = (int[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < iAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.SetValue(ObjType.Name, sIndex, iAray[i]);
                        Log.Trace(sIndex, iAray[i].ToString());
                    }
                }
                else if (MemType == typeof(bool[]))
                {
                    bool[] bAray = (bool[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < bAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.SetValue(ObjType.Name, sIndex, bAray[i]);
                        Log.Trace(sIndex, bAray[i].ToString());
                    }
                }
                else if (MemType == typeof(double[]))
                {
                    double[] dAray = (double[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < dAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.SetValue(ObjType.Name, sIndex, dAray[i]);
                        Log.Trace(sIndex, dAray[i].ToString());
                    }
                }
                else if (MemType == typeof(string[]))
                {
                    string[] sAray = (string[])MemInfo.GetValue(_oObj);

                    string sIndex;
                    for (int i = 0; i < sAray.Length; i++)
                    {
                        sIndex = string.Format("{0}({1})", sMemName, i);
                        _cConfig.SetValue(ObjType.Name, sIndex, sAray[i]);
                        Log.Trace(sIndex, sAray[i].ToString());
                    }
                }
            }
            return(true);
        }