Пример #1
0
        public void Construct_GridLength_two_parameter_ctors_one_isenum()
        {
            var tf = new TypeFinder();

            var ctor = new XenConstructor
            {
                TypeName   = typeof(GridLength).AssemblyQualifiedName,
                Parameters = new[]
                {
                    new XenParameter
                    {
                        TypeName      = "System.Double",
                        ParameterName = "value",
                        Position      = 0,
                        Value         = 7
                    },
                    new XenParameter
                    {
                        TypeName      = typeof(GridUnitType).FullName,
                        ParameterName = "type",
                        Position      = 1,
                        Value         = GridUnitType.Star
                    }
                }
            };

            var obj    = XenConstructorMethods.Construct(tf, ctor);
            var casted = (GridLength)obj;

            Assert.AreEqual(7, casted.Value);
            Assert.AreEqual(GridUnitType.Star, casted.GridUnitType);
        }
Пример #2
0
        public void Construct_GridLength_single_numeric_parameter_ctor()
        {
            var tf = new TypeFinder();

            var ctor = new XenConstructor
            {
                TypeName   = typeof(GridLength).AssemblyQualifiedName,
                Parameters = new[]
                {
                    new XenParameter
                    {
                        TypeName      = "System.Double",
                        ParameterName = "value",
                        Position      = 0,
                        Value         = 5
                    }
                }
            };

            var obj    = XenConstructorMethods.Construct(tf, ctor);
            var casted = (GridLength)obj;

            Assert.AreEqual(5, casted.Value);
            Assert.AreEqual(GridUnitType.Absolute, casted.GridUnitType);
        }
Пример #3
0
        public void Rectangle_constructors()
        {
            var ctors = XenConstructorMethods.GetConstructors(typeof(Rectangle));
            var c1    = ctors.Any(p => p.DisplayName == "Rectangle(Double x, Double y, Double width, Double height)");
            var c2    = ctors.Any(p => p.DisplayName == "Rectangle(Point loc, Size sz)");

            Assert.IsTrue(c1, "c1");
            Assert.IsTrue(c2, "c2");
        }
Пример #4
0
        protected override void OnExecute(XenMessageContext ctx)
        {
            if (ctx.Request == null)
            {
                return;
            }

            var req = ctx.Get <GetConstructorsRequest>();

            if (req == null)
            {
                return;
            }

            var type = TypeFinder.Find(req.TypeName);

            if (type == null)
            {
                return;
            }

            var ctors = XenConstructorMethods.GetConstructors(type);

            foreach (var ctor in ctors)
            {
                foreach (var p in ctor.Parameters)
                {
                    var pType = TypeFinder.Find(p.TypeName);

                    p.XenType = new XenType
                    {
                        Descriptor = Descriptor.GetDescriptors(pType),
                        FullName   = pType.FullName,
                    };

                    Descriptor.SetPossibleValues(pType, p.XenType);
                }
            }

            ctx.SetResponse <GetConstructorsResponse>(res =>
            {
                var descs = Descriptor.GetDescriptors(type);

                res.Type = new XenType
                {
                    FullName     = req.TypeName,
                    Descriptor   = descs,
                    Constructors = ctors
                };
            });
        }
Пример #5
0
        public void Should_find_structure_constructors()
        {
            var ctors = XenConstructorMethods.GetConstructors(typeof(GridLength));

            var c1 = ctors[0];
            var c2 = ctors[1];

            Assert.AreEqual(2, ctors.Length);
            Assert.AreEqual(typeof(GridLength).AssemblyQualifiedName, c1.TypeName);

            Assert.AreEqual("value", c2.Parameters[0].ParameterName);
            Assert.AreEqual("type", c2.Parameters[1].ParameterName);
            Assert.AreEqual(typeof(GridUnitType).FullName, c2.Parameters[1].TypeName);
        }
Пример #6
0
        protected override void OnExecute(XenMessageContext ctx)
        {
            if (ctx.Request == null)
            {
                return;
            }

            var req = ctx.Get <CallConstructorRequest>();

            if (req == null)
            {
                return;
            }

            var error   = string.Empty;
            var success = false;
            var obj     = XenConstructorMethods.Construct(TypeFinder, req.Constructor);

            if (obj != null)
            {
                try
                {
                    SetPropertyValue(req.WidgetId, req.Property.Path, obj, false, false);
                }
                catch (Exception ex)
                {
                    error   = ex.ToString();
                    success = false;
                }

                success = true;
            }

            ctx.SetResponse <CallConstructorResponse>(res =>
            {
                res.ErrorMessage = error;
                res.Successful   = success;
            });
        }