private static void ChangePropertyValues(GuiControl control, Dictionary <string, object> setters) { var targetType = control.GetType(); foreach (var propertyName in setters.Keys) { var propertyInfo = targetType.GetRuntimeProperty(propertyName); var value = setters[propertyName]; if (propertyInfo != null) { if (propertyInfo.CanWrite) { propertyInfo.SetValue(control, value); } // special case when we have a list of items as objects (like on a list box) if (propertyInfo.PropertyType == typeof(List <object>)) { var items = (List <object>)value; var addMethod = propertyInfo.PropertyType.GetRuntimeMethod("Add", new[] { typeof(object) }); foreach (var item in items) { addMethod.Invoke(propertyInfo.GetValue(control), new[] { item }); } } } } }
private static void ChangePropertyValues(GuiControl control, Dictionary <string, object> setters) { var targetType = control.GetType(); foreach (var propertyName in setters.Keys) { var propertyInfo = targetType.GetRuntimeProperty(propertyName); var value = setters[propertyName]; if (propertyInfo != null && propertyInfo.CanWrite) { propertyInfo.SetValue(control, value); } } }
/// <summary>Renders a single control</summary> /// <param name="controlToRender">Control that will be rendered</param> private void RenderControl(GuiControl controlToRender) { IControlRendererAdapter renderer = null; var controlType = controlToRender.GetType(); // If this is an actual instance of the 'Control' class, don't render it. // Such instances can be used to construct invisible containers, and are most // prominently embodied in the 'desktop' control that hosts the whole GUI. if ((controlType == typeof(GuiControl)) || (controlType == typeof(GuiDesktopControl))) { return; } // Find a renderer for this control. If no renderer for the control itself can // be found, look for a renderer then can render its base class. This allows // controls to inherit from existing controls, remaining renderable (but also // gaining the ability to accept a specialized renderer for the new derived // control class!). Normally, this loop will finish without any repetitions. while (controlType != typeof(object)) { var found = _renderers.TryGetValue(controlType, out renderer); if (found) { break; } // Next, try the base class of this type controlType = controlType.GetTypeInfo().BaseType; } // If we found a renderer, use it to render the control if (renderer != null) { renderer.Render(controlToRender, _flatGuiGraphics); } }