コード例 #1
0
        private Point CalculatePoint()
        {
            var point = (Point)_pointConverter
                        .ConvertFromInvariantString(_formattedMultiplierString);
            double multiplier = GetFinalLengthMultiplier();

            return(new Point(point.X * multiplier, point.Y * multiplier));
        }
コード例 #2
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }
            string strValue = value as string;

            if (strValue != null)
            {
                try
                {
                    return(_pointConverter.ConvertFromInvariantString(strValue));
                }
                catch
                {
                }
            }

            return(Binding.DoNothing);
        }
コード例 #3
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);
        }
コード例 #4
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;
                }
            }
        }
コード例 #5
0
ファイル: ConversionHelper.cs プロジェクト: vpalodic/Holodeck
 public static Point StringToPoint(string str)
 {
     return((Point)_pc.ConvertFromInvariantString(str));
 }