/// <summary>
        /// Creates a <see cref="LogicalFont"/> from a string.
        /// </summary>
        public static LogicalFont ToLogicalFont(string value)
        {
            var convert = new FontConverter();

            using (var font = (Font)convert.ConvertFromInvariantString(value))
                return(ToLogicalFont(font));
        }
Exemple #2
0
        private void frmMain_Shown(object sender, EventArgs e)
        {
            //加载报文配置
            Cmd.LoadCmd();
            menuShowLogCmd.Checked   = Cmd.C_SHOW_LOG == "TRUE" ? true : false;
            menuShowRcvData.Checked  = Cmd.C_SHOW_RCV == "TRUE" ? true : false;
            menuShowSendData.Checked = Cmd.C_SHOW_SEND == "TRUE" ? true : false;
            menuShowCmdHead.Checked  = Cmd.C_SHOW_HEAD == "TRUE" ? true : false;
            menuShowCmdTime.Checked  = Cmd.C_SHOW_TIME == "TRUE" ? true : false;
            FontConverter fc = new FontConverter();

            try
            {
                rtCmd.Font = (Font)fc.ConvertFromInvariantString(Cmd.C_FONT);
            }
            catch (NotSupportedException)
            {
                Cmd.C_FONT = fc.ConvertToInvariantString(rtCmd.Font);
                Console.WriteLine("读取字体异常,已恢复:" + Cmd.C_FONT);
                throw;
            }

            //界面初始化
            Function.LoadFunction();
            if (((Function.F_MAIN_X) != "NULL") && ((Function.F_MAIN_Y) != "NULL"))
            {
                int left = Convert.ToInt32(Function.F_MAIN_X);
                int top  = Convert.ToInt32(Function.F_MAIN_Y);
                if (left >= 0 && top >= 0)
                {
                    this.Left = left;
                    this.Top  = top;
                    if (Convert.ToInt32(Function.F_MAIN_WIDTH) >= this.MinimumSize.Width)
                    {
                        this.Width = Convert.ToInt32(Function.F_MAIN_WIDTH);
                    }
                    if (Convert.ToInt32(Function.F_MAIN_HEIGHT) >= this.MinimumSize.Height)
                    {
                        this.Height = Convert.ToInt32(Function.F_MAIN_HEIGHT);
                    }
                }
            }
            cbRH.SelectedIndex  = 0;
            cbAPP.SelectedIndex = 0;

            //串口配置初始化
            sp1 = new SerialPort();
            Control.CheckForIllegalCrossThreadCalls = false;    //这个类中我们不检查跨线程的调用是否合法(因为.net 2.0以后加强了安全机制,,不允许在winform中直接跨线程访问控件的属性)
            sp1.DataReceived += new SerialDataReceivedEventHandler(sp1_DataReceived);
            sp1.DtrEnable     = true;
            sp1.RtsEnable     = true;
            sp1.Close();

            rtCmd.Clear();
            funcOutputLog("准备就绪,等待串口开启。");

            //打开串口
            funcOpenSerialPort();
        }
Exemple #3
0
        public Font ConvertFromMemberFont()
        {
            FontConverter conv = new FontConverter();

            return
                (TreeViewFont == null
                ? null
                : conv.ConvertFromInvariantString(TreeViewFont) as Font);
        }
Exemple #4
0
 public void ParseFromXml(XmlDocument xmlDocument)
 {
     GobalColumnList = new List <QuickReportCore.Objects.Column>();
     System.Xml.XmlNodeList nodeList = xmlDocument.SelectNodes("//" + ucColumnObject.XmlAttrDic.ColumnObject.ToString());
     Objects.Column[]       columns  = new QuickReportCore.Objects.Column[nodeList.Count];
     foreach (System.Xml.XmlNode node in nodeList)
     {
         Objects.Column column = new QuickReportCore.Objects.Column();
         column.ID              = Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tID.ToString(), string.Empty);
         column.Name            = Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tName.ToString(), string.Empty);
         column.Filter          = Convert.ToBoolean(Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.bFilter.ToString(), "0")));
         column.Use             = Convert.ToBoolean(Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.bUse.ToString(), "0")));
         column.Sort            = Convert.ToBoolean(Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.bSort.ToString(), "0")));
         column.TotalColumn     = Convert.ToBoolean(Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.bTotalColumn.ToString(), "0")));
         column.TotalRow        = Convert.ToBoolean(Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.bTotalRow.ToString(), "0")));
         column.SortId          = Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tSortID.ToString(), "0"));
         column.IsNumber        = Convert.ToBoolean(Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.bIsNumber.ToString(), "0")));
         column.DecimalPlace    = Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tDecimalPlace.ToString(), "0"));
         column.Font            = fc.ConvertFromInvariantString(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tFont.ToString(), string.Empty)) as Font;
         column.Color           = System.Drawing.ColorTranslator.FromHtml(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tColor.ToString(), string.Empty));
         column.HAligment       = (FarPoint.Win.Spread.CellHorizontalAlignment)Enum.Parse(typeof(FarPoint.Win.Spread.CellHorizontalAlignment), Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tHAligment.ToString(), FarPoint.Win.Spread.CellHorizontalAlignment.General.ToString()));
         column.VAligment       = (FarPoint.Win.Spread.CellVerticalAlignment)Enum.Parse(typeof(FarPoint.Win.Spread.CellVerticalAlignment), Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tVAligment.ToString(), FarPoint.Win.Spread.CellVerticalAlignment.General.ToString()));
         column.Union           = Convert.ToBoolean(Convert.ToInt32(Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.bUnion.ToString(), "0")));
         column.ValueTransType  = (QuickReportCore.Class.NumberCellTypePlus.ValueTranslateType)Enum.Parse(typeof(QuickReportCore.Class.NumberCellTypePlus.ValueTranslateType), Managers.Functions.GetNodeAttrValue(node, ucColumnObject.XmlAttrDic.tValueTranslateType.ToString(), QuickReportCore.Class.NumberCellTypePlus.ValueTranslateType.转换.ToString()));
         columns[column.SortId] = column.Clone();
         GobalColumnList.Add(column.Clone());
     }
     ucColumnObjectControls = new Hashtable();
     for (int i = 0; i < columns.Length; i++)
     {
         if (!ucColumnObjectControls.Contains(columns[i].ID))
         {
             ucColumnObject uc = new ucColumnObject();
             uc.ActivateOn += new ucColumnObject.ActivateHandle(uc_ActivateOn);
             uc.Column      = columns[i];
             ucColumnObjectControls.Add(columns[i].ID, uc);
         }
     }
     pnlColumns.Controls.Clear();
     foreach (DictionaryEntry de in ucColumnObjectControls)
     {
         pnlColumns.Controls.Add(de.Value as Control);
         int i = (de.Value as ucColumnObject).Column.SortId;
         if (i == 0)
         {
             (de.Value as ucColumnObject).Location = new Point(leftMargin, topMargin);
         }
         else
         {
             (de.Value as ucColumnObject).Location = new Point(leftMargin, topMargin + (ucColumnObjectControls[columns[i].ID] as ucColumnObject).Height * i + eatchMargin * i);
         }
     }
 }
Exemple #5
0
        public Font ConvertFromMemberFont()
        {
            FontConverter conv = new FontConverter();

            if (this.TreeViewFont != null)
            {
                return(conv.ConvertFromInvariantString(this.TreeViewFont) as Font);
            }
            else
            {
                return(null);
            }
        }
 public void ParseFromXml(XmlNodeList xmlNodeList)
 {
     fpMain_Sheet1.RowCount = xmlNodeList.Count;
     for (int i = 0; i < xmlNodeList.Count; i++)
     {
         int rowIndex = Convert.ToInt32(Managers.Functions.GetNodeAttrValue(xmlNodeList[i], XmlAttrDic.tRowIndex.ToString(), "0"));
         FarPoint.Win.Spread.Cell cell = fpMain_Sheet1.Cells[rowIndex, 0];
         cell.Text                           = Managers.Functions.GetNodeAttrValue(xmlNodeList[i], XmlAttrDic.tText.ToString(), string.Empty);
         cell.Font                           = fc.ConvertFromInvariantString(Managers.Functions.GetNodeAttrValue(xmlNodeList[i], XmlAttrDic.tFont.ToString(), string.Empty)) as Font;
         cell.ForeColor                      = System.Drawing.ColorTranslator.FromHtml(Managers.Functions.GetNodeAttrValue(xmlNodeList[i], XmlAttrDic.tColor.ToString(), string.Empty));
         cell.HorizontalAlignment            = (FarPoint.Win.Spread.CellHorizontalAlignment)Enum.Parse(typeof(FarPoint.Win.Spread.CellHorizontalAlignment), Managers.Functions.GetNodeAttrValue(xmlNodeList[i], XmlAttrDic.tHAligment.ToString(), FarPoint.Win.Spread.CellHorizontalAlignment.General.ToString()));
         cell.VerticalAlignment              = (FarPoint.Win.Spread.CellVerticalAlignment)Enum.Parse(typeof(FarPoint.Win.Spread.CellVerticalAlignment), Managers.Functions.GetNodeAttrValue(xmlNodeList[i], XmlAttrDic.tVAligment.ToString(), FarPoint.Win.Spread.CellVerticalAlignment.General.ToString()));
         fpMain_Sheet1.Rows[rowIndex].Height = Convert.ToInt64(Managers.Functions.GetNodeAttrValue(xmlNodeList[i], XmlAttrDic.tHeight.ToString(), "0"));
     }
 }
        internal static Font FontFromString(string fontString)
        {
            string text = fontString;
            byte   b    = 1;
            bool   flag = false;
            int    num  = fontString.IndexOf(", GdiCharSet=", StringComparison.Ordinal);

            if (num >= 0)
            {
                string text2 = fontString.Substring(num + 13);
                int    num2  = text2.IndexOf(",", StringComparison.Ordinal);
                if (num2 >= 0)
                {
                    text2 = text2.Substring(0, num2);
                }
                b = (byte)int.Parse(text2, CultureInfo.InvariantCulture);
                if (text.Length > num)
                {
                    text = text.Substring(0, num);
                }
            }
            num = fontString.IndexOf(", GdiVerticalFont", StringComparison.Ordinal);
            if (num >= 0)
            {
                flag = true;
                if (text.Length > num)
                {
                    text = text.Substring(0, num);
                }
            }
            Font font = (Font)fontConverter.ConvertFromInvariantString(text);

            if (flag || b != 1)
            {
                Font result = new Font(font.Name, font.SizeInPoints, font.Style, GraphicsUnit.Point, b, flag);
                font.Dispose();
                return(result);
            }
            return(font);
        }
        /// <summary>
        /// 参数类型转换函数,将参数转换成目标类型的值。
        /// 由于.net自带的参数转换函数不支持某些类型的转换,所以重写了该方法。
        /// </summary>
        /// <param name="value">待转换的值</param>
        /// <param name="targetType">目标类型</param>
        /// <returns>目标类型的值</returns>
        /// <author>宋佳恒</author>
        /// <date>2017-03-29</date>
        /// <exception cref="System.InvalidCastException">类型转换异常</exception>
        protected static object ConvertValueType(object value, Type targetType)
        {
            //转换后的值
            object transValue = null;

            try
            {
                if (null == value)
                {
                    throw new InvalidCastException("待转换的值为空");
                }
                if (null == targetType)
                {
                    throw new InvalidCastException("目标类型为空");
                }
                string bathPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                switch (targetType.ToString())
                {
                case "System.Drawing.Color": transValue = System.Drawing.ColorTranslator.FromHtml((string)value); break;

                case "System.Drawing.Bitmap": transValue = Image.FromFile(bathPath + "\\" + (string)value); break;

                case "System.Drawing.Image": transValue = Image.FromFile(bathPath + "\\" + (string)value); break;

                case "System.Windows.Forms.ImageLayout": transValue = (ImageLayout)Enum.Parse(typeof(ImageLayout), (string)value); break;

                case "System.Drawing.Font": FontConverter fc = new FontConverter();
                    transValue = fc.ConvertFromInvariantString((string)value); break;

                default: transValue = Convert.ChangeType(value, targetType); break;
                }
            }
            catch (InvalidCastException ex)
            {
                throw new InvalidCastException("值" + value + "转换为" + targetType + "失败");
            }
            return(transValue);
        }
Exemple #9
0
        public Font GetFontEx(string name)
        {
            if (GdiCacheFonts.ContainsKey(name))
            {
                return(GdiCacheFonts[name]);
            }
            else
            {
                string fontName = name;
                string fontSize = "";
                if (name.IndexOf(',') != -1)
                {
                    fontName = name.Substring(0, name.IndexOf(',')).Trim();
                    fontSize = name.Substring(name.IndexOf(',') + 1).Trim();
                }

                double userBaseSize = Engine.Instance.Storage.GetFloat("gui.font.normal.size");
                if (userBaseSize == 0)
                {
                    string systemFont = Core.Platform.Instance.GetSystemFont();
                    int    posSize    = systemFont.IndexOf(",");

                    string strSize = systemFont.Substring(posSize + 1);
                    if (posSize != -1)
                    {
                        double.TryParse(strSize, out userBaseSize);
                    }

                    if (userBaseSize == 0)
                    {
                        userBaseSize = 10;
                    }
                }

                if ((fontName == "System") || (fontName == "SystemMonospace"))
                {
                    string systemFont = "";
                    if (fontName == "System")
                    {
                        if (Engine.Instance.Storage.Get("gui.font.normal.name") != "")
                        {
                            systemFont = Engine.Instance.Storage.Get("gui.font.normal.name");
                        }
                        else
                        {
                            systemFont = Core.Platform.Instance.GetSystemFont();
                        }
                    }

                    else if (fontName == "SystemMonospace")
                    {
                        systemFont = Core.Platform.Instance.GetSystemFontMonospace();
                    }
                    int posSize = systemFont.IndexOf(",");
                    if (posSize != -1)
                    {
                        systemFont = systemFont.Substring(0, posSize);
                    }
                    fontName = systemFont;
                }

                if (fontSize == "normal")
                {
                    fontSize = userBaseSize.ToString(CultureInfo.InvariantCulture) + "pt";
                }
                else if (fontSize == "big")
                {
                    fontSize = (userBaseSize * 1.25).ToString(CultureInfo.InvariantCulture) + "pt";
                }

                string name2 = fontName + "," + fontSize;

                FontConverter fontConverter = new FontConverter();
                Font          f             = fontConverter.ConvertFromInvariantString(name2) as Font;
                GdiCacheFonts[name] = f;

                return(f);
            }
        }
Exemple #10
0
        private bool ProcessSetValue(Type type, string name, string newvalue)
        {
            if (type == typeof(string))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { newvalue });
                return(true);
            }

            if (type == typeof(bool))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { bool.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(int))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { int.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(long))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { long.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(decimal))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { decimal.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(float))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { float.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(double))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { double.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(char))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { char.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Enum) || type.BaseType == typeof(Enum))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Enum.Parse(type, newvalue) });
                return(true);
            }

            if (type == typeof(Single))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Single.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Byte))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Byte.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(SByte))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { SByte.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Int16))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Int16.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Int32))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Int32.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Int64))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Int64.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(UInt16))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { UInt16.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(UInt32))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { UInt32.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(UInt64))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { UInt64.Parse(newvalue) });
                return(true);
            }

            // 20080827 : DateTimeConvertor.ConvertToInvariantString(DateTime.MinValue) return empty string ""
            //            which cannot be parsed by following culture specific method.

            //if( type == typeof( DateTime ) )
            //{
            //    this.GetType().InvokeMember( name,
            //        /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
            //        BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField ,
            //        null, this, new object[]{ DateTime.Parse(newvalue) } );
            //    return true;
            //}

            if (type == typeof(TimeSpan))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { TimeSpan.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Color))
            {
                ColorConverter cc = new ColorConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Font))
            {
                FontConverter cc = new FontConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Point))
            {
                PointConverter cc = new PointConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Rectangle))
            {
                RectangleConverter cc = new RectangleConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Size))
            {
                SizeConverter cc = new SizeConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            //if (type == typeof(Type))
            //{
            //    Type newType = null;
            //    if (newvalue != null && newvalue.Length > 0)
            //    {
            //        newType = Type.GetType(newvalue, true);
            //    }

            //    this.GetType().InvokeMember(name,
            //        /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
            //        BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
            //        null, this, new object[] { newType });
            //    return true;
            //}

            if (!XObjectHelper.IsXBaseType(type))
            {
                TypeConverter tc = TypeDescriptor.GetConverter(type);
                if (tc == null)
                {
                    return(true);
                }

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { tc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            return(true);
        }
Exemple #11
0
        private void SetProperty(PropertyInfo p, object val)
        {
            if (p == null)
            {
                return;
            }

            if (val == null)
            {
                this.GetType().InvokeMember(p.Name,
                                            BindingFlags.DeclaredOnly | BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty,
                                            null, this, new object[] { null });
            }
            else
            {
                string str = val.ToString();

                if (p.PropertyType == typeof(string))
                {
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { str });
                    return;
                }

                if (p.PropertyType == typeof(DateTime))
                {
                    DateTime v = DateTime.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(decimal))
                {
                    decimal v = decimal.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(int))
                {
                    int v = int.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(long))
                {
                    long v = long.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(float))
                {
                    float v = float.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(double))
                {
                    double v = double.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Color))
                {
                    ColorConverter cc = new ColorConverter();
                    Color          v  = (Color)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Font))
                {
                    FontConverter cc = new FontConverter();
                    Font          v  = (Font)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Point))
                {
                    PointConverter cc = new PointConverter();
                    Point          v  = (Point)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Size))
                {
                    SizeConverter cc = new SizeConverter();
                    Size          v  = (Size)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Rectangle))
                {
                    RectangleConverter cc = new RectangleConverter();
                    Rectangle          v  = (Rectangle)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }
            }
        }