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); }
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); }
public void Empty_params_should_return_default_ctor() { var ctor = new XenConstructor { TypeName = typeof(Rectangle).FullName }; Assert.AreEqual("Rectangle()", ctor.DisplayName); }
public static object Construct(ITypeFinder finder, XenConstructor ctor) { var cType = finder.Find(ctor.TypeName); if (cType == null) { return(null); } object[] ps = null; if (ctor.Parameters.Any()) { ps = ctor .Parameters .OrderBy(c => c.Position) .Select(p => { if (p == null) { return(null); } var pType = finder.Find(p.TypeName); if (pType == null) { return(null); } object val; try { if (pType.GetTypeInfo().IsEnum) { val = ReflectionMethods.CreateEnum(pType, p.Value); } else { val = Convert.ChangeType(p.Value, pType); } } catch (Exception) { val = p.Value; } return(val); }).ToArray(); } return(Activator.CreateInstance(cType, ps)); }
public void CallConstructor(string widgetId, XenProperty property, XenConstructor ctor) { if (ctor == null) { return; } var r = XenMessage.Create <CallConstructorRequest>(); r.Constructor = ctor; r.Property = property; r.WidgetId = widgetId; _socket.Send(r); }
public bool ShowEditors(VisualTreeNode node, XenConstructor ctor) { try { Clear(); var editors = new List <IPropertyEditorModel>(); foreach (var p in ctor.Parameters.OrderBy(p => p.ParameterName)) { var model = ToolboxApp.Editors.Create(p); if (model == null) { ToolboxApp.Log.Error($"Error creating {p.ShortTypeName} property editor."); continue; } p.Value = null; model.VisualNode = node; editors.Add(model); var captured = p; model.Saving += (sender, args) => { captured.Value = args.ToolboxValue; }; } foreach (var editor in editors) { Editors.Add(editor); } DataStore = Editors; if (Editors.Any()) { ScrollToRow(0); } } catch (Exception e) { ToolboxApp.Log.Error(e, $"Error while showing property editors for {node.DisplayName}."); return(false); } return(true); }
public static XenConstructor[] GetConstructors(Type type) { if (type == null) { return new XenConstructor[] {} } ; var xctors = new List <XenConstructor>(); var tctors = type.GetConstructors(); foreach (var tctor in tctors) { if (tctor.IsAbstract) { continue; } var xctor = new XenConstructor(); var xparams = new List <XenParameter>(); xctor.TypeName = type.AssemblyQualifiedName; foreach (var pi in tctor.GetParameters()) { var xparam = new XenParameter { ParameterName = pi.Name, Position = pi.Position, TypeName = pi.ParameterType.FullName, IsTypeEnum = pi.ParameterType.GetTypeInfo().IsEnum }; xparams.Add(xparam); } xctor.Parameters = xparams.ToArray(); xctors.Add(xctor); } return(xctors.ToArray()); } }
public void No_typename_should_return_null_displayname() { var ctor = new XenConstructor(); Assert.IsNull(ctor.DisplayName); }