예제 #1
0
        private void SetObjectData(FieldInfo field, PropertyInfo propSource, PropertyInfo parentProp, object propObject,
                                   object parentObject)
        {
            var pType  = propSource.PropertyType;
            var pFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;

            //if (pType == typeof(Unit))
            //{
            //    var v = new Unit((string)field.GetValue(this));
            //    propSource.SetValue(propObject, v, null);
            //    return;
            //}

            if (pType == typeof(Color))
            {
                var c = RadarUtils.GetColorFromHexString((string)field.GetValue(this));
                propSource.SetValue(propObject, c, null);
                return;
            }

            if (propObject is Font)
            {
                var       oldFont = ((Font)propObject).Clone() as Font;
                FontStyle oldStyle;
                var       pPath     = field.Name.Split('_');
                var       shortname = pPath[pPath.Length - 1];
                switch (shortname)
                {
                case "Name":
                    propObject = new Font((string)field.GetValue(this), oldFont.Size, oldFont.Style);
                    break;

                case "Size":
                    propObject = new Font(oldFont.Name, (int)field.GetValue(this), oldFont.Style);
                    break;

                case "Bold":
                    oldStyle = oldFont.Style;
                    if ((bool)field.GetValue(this))
                    {
                        if (!oldStyle.HasFlag(FontStyle.Bold))
                        {
                            oldStyle |= FontStyle.Bold;
                        }
                    }
                    else if (oldStyle.HasFlag(FontStyle.Bold))
                    {
                        oldStyle ^= FontStyle.Bold;
                    }
                    propObject = new Font(oldFont.Name, oldFont.Size, oldStyle);
                    break;

                case "Italic":
                    oldStyle = oldFont.Style;
                    if ((bool)field.GetValue(this))
                    {
                        if (!oldStyle.HasFlag(FontStyle.Italic))
                        {
                            oldStyle |= FontStyle.Italic;
                        }
                    }
                    else if (oldStyle.HasFlag(FontStyle.Italic))
                    {
                        oldStyle ^= FontStyle.Italic;
                    }
                    propObject = new Font(oldFont.Name, oldFont.Size, oldStyle);
                    break;

                case "Underline":
                    oldStyle = oldFont.Style;
                    if ((bool)field.GetValue(this))
                    {
                        if (!oldStyle.HasFlag(FontStyle.Underline))
                        {
                            oldStyle |= FontStyle.Underline;
                        }
                    }
                    else if (oldStyle.HasFlag(FontStyle.Underline))
                    {
                        oldStyle ^= FontStyle.Underline;
                    }
                    propObject = new Font(oldFont.Name, oldFont.Size, oldStyle);
                    break;

                case "Strikeout":
                    oldStyle = oldFont.Style;
                    if ((bool)field.GetValue(this))
                    {
                        if (!oldStyle.HasFlag(FontStyle.Strikeout))
                        {
                            oldStyle |= FontStyle.Strikeout;
                        }
                    }
                    else if (oldStyle.HasFlag(FontStyle.Strikeout))
                    {
                        oldStyle ^= FontStyle.Strikeout;
                    }
                    propObject = new Font(oldFont.Name, oldFont.Size, oldStyle);
                    break;
                }
                parentProp.SetValue(parentObject, propObject, null);
                return;
            }

            propSource.SetValue(propObject, field.GetValue(this), null);
        }