public void Construct_GridLength_two_parameter_ctors_one_isenum() { var tf = new TypeFinder(); var ctor = new UIConstructor { TypeName = typeof(GridLength).AssemblyQualifiedName, Parameters = new[] { new UIParameter { TypeName = "System.Double", ParameterName = "value", Position = 0, Value = 7 }, new UIParameter { TypeName = typeof(GridUnitType).FullName, ParameterName = "type", Position = 1, Value = GridUnitType.Star } } }; var obj = UIConstructorMethods.Construct(tf, ctor); var casted = (GridLength)obj; Assert.AreEqual(7, casted.Value); Assert.AreEqual(GridUnitType.Star, casted.GridUnitType); }
public void Construct_GridLength_single_numeric_parameter_ctor() { var tf = new TypeFinder(); var ctor = new UIConstructor { TypeName = typeof(GridLength).AssemblyQualifiedName, Parameters = new[] { new UIParameter { TypeName = "System.Double", ParameterName = "value", Position = 0, Value = 5 } } }; var obj = UIConstructorMethods.Construct(tf, ctor); var casted = (GridLength)obj; Assert.AreEqual(5, casted.Value); Assert.AreEqual(GridUnitType.Absolute, casted.GridUnitType); }
public void Rectangle_constructors() { var ctors = UIConstructorMethods.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"); }
protected override void OnExecute(UIMessageContext 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 = UIConstructorMethods.GetConstructors(type); foreach (var ctor in ctors) { foreach (var p in ctor.Parameters) { var pType = TypeFinder.Find(p.TypeName); p.UIType = new UIType { Descriptor = Descriptor.GetDescriptors(pType), FullName = pType.FullName, }; Descriptor.SetPossibleValues(pType, p.UIType); } } ctx.SetResponse <GetConstructorsResponse>(res => { var descs = Descriptor.GetDescriptors(type); res.Type = new UIType { FullName = req.TypeName, Descriptor = descs, Constructors = ctors }; }); }
public void Should_find_structure_constructors() { var ctors = UIConstructorMethods.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); }
protected override void OnExecute(UIMessageContext ctx) { if (ctx.Request == null) { return; } var req = ctx.Get <CallConstructorRequest>(); if (req == null) { return; } var error = string.Empty; var success = false; var obj = UIConstructorMethods.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; }); }