private IComponent BuildContainer(object parentInstance, PropertyInfo propertyInfo, PropertyInfo[] propertyInfos) { var groupContainer = _componentManager.CreateComponentFromComponentType <IGroupContainer>(); var settings = CreateSettingBuilder(propertyInfo).Build(); SettingBinder.BindContainer(groupContainer, propertyInfo, settings); var currentInstance = propertyInfo.GetValue(parentInstance); if (currentInstance == null && AllowAutoCreateInstanceIfMissing) { propertyInfo.SetValue( parentInstance, currentInstance = Activator.CreateInstance(propertyInfo.PropertyType)); } foreach (var childPropertyInfo in propertyInfos) { var component = BuildRecursive(currentInstance, childPropertyInfo); if (component == null) { continue; } groupContainer.AddChild(component); } return(groupContainer); }
/// <summary> /// Builds a UI from config data and binds its properties to this the UI. /// </summary> /// <param name="config"> /// The config data that will be used to determine the UI structure and binds /// its properties to the UI. /// </param> /// <typeparam name="T"> /// Type of the UI which is an <see cref="IContainer"/>. /// </typeparam> /// <returns>The UI instance that is created from the config data.</returns> public T Build <T>(object config) where T : IContainer { Precondition.ArgumentNotNull(config, nameof(config)); Precondition.PropertyNotNull(SettingBinder, nameof(SettingBinder)); CheckFactories(); var container = _componentManager.CreateComponentFromComponentType <IContainer>(typeof(T)); var configType = config.GetType(); var settings = CreateSettingBuilder(configType).Build(); SettingBinder.BindContainer(container, configType, settings); foreach (var propertyInfo in configType.GetProperties()) { var component = BuildRecursive(config, propertyInfo); if (component == null) { continue; } container.AddChild(component); } return((T)container); }