예제 #1
0
        /// <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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        private UiManager()
        {
            _componentManager = new ComponentManager();
            _settingBinder    = new SettingBinder();

            SettingBinder              = new SettingBinder();
            LayoutOptionsFactory       = new DefaultLayoutOptionsFactory();
            SizeOptionsFactory         = new DefaultSizeOptionsFactory();
            DateTimeOptionsFactory     = new DefaultDateTimeOptionsFactory();
            ContainerAppearanceFactory = new DefaultContainerAppearanceFactory();
            EditorAppearanceFactory    = new DefaultEditorAppearanceFactory();
        }
예제 #4
0
        /// <summary>
        /// Copy whole settings from source to this instance.
        /// </summary>
        public void Copy(UiManager source)
        {
            Precondition.ArgumentNotNull(source, nameof(source));

            _componentManager.Copy(source._componentManager);
            _settingBinder = source._settingBinder;

            SettingBinder = source.SettingBinder;

            LayoutManagerFactory       = source.LayoutManagerFactory;
            LayoutOptionsFactory       = source.LayoutOptionsFactory;
            SizeOptionsFactory         = source.SizeOptionsFactory;
            DateTimeOptionsFactory     = source.DateTimeOptionsFactory;
            ContainerAppearanceFactory = source.ContainerAppearanceFactory;
            EditorAppearanceFactory    = source.EditorAppearanceFactory;

            AllowAutoCreateInstanceIfMissing = source.AllowAutoCreateInstanceIfMissing;
        }
예제 #5
0
        private IComponent BuildEditor(object parentInstance, PropertyInfo propertyInfo)
        {
            var settings = CreateSettingBuilder(propertyInfo)
                           .SetReferenceInfo(new ReferenceInfo
            {
                PropertyInfo = propertyInfo,
                Source       = parentInstance
            })
                           .Build();

            var componentType = settings.Get <Type>("componentType");
            var component     = ObjectUtils.IsGenericList(propertyInfo.PropertyType)
                ? CreateListEditor(componentType, propertyInfo.PropertyType)
                : CreateNormalEditor(componentType, propertyInfo.PropertyType);

            SettingBinder.BindEditor(component, propertyInfo, settings);

            return(component);
        }