Exemple #1
0
        public static DataContentCache BuildCache(Type type)
        {
            DataContentCache dataContentCache = new DataContentCache(type);
            Type             frameworkType    = typeof(FrameworkElement);

            foreach (PropertyInfo propertyInfo in type.GetProperties(PropertyBindingFlags).OrderBy(p => p.GetCustomAttribute <DataProperty>()?.Order))
            {
                DataProperty dataProperty = propertyInfo.GetCustomAttribute <DataProperty>();
                if (dataProperty == null || !frameworkType.IsAssignableFrom(dataProperty.ControlType))
                {
                    continue;
                }
                ConstructorInfo  ctor = dataProperty.ControlType.GetConstructor(new[] { typeof(object[]) });
                FrameworkElement frameworkElement;
                if (ctor == null)
                {
                    frameworkElement = (FrameworkElement)Activator.CreateInstance(dataProperty.ControlType);
                }
                else
                {
                    frameworkElement = (FrameworkElement)Activator.CreateInstance(dataProperty.ControlType, dataProperty.Params);
                }
                if (frameworkElement == null)
                {
                    continue;
                }
                DataCategory dataCategory = propertyInfo.GetCustomAttribute <DataCategory>();
                if (dataCategory != null)
                {
                    dataContentCache.AddElement(new TextBlock {
                        Text = NebulaClient.GetLocString(dataCategory.Category), FontSize = 24
                    });
                }
                DependencyProperty dependencyProperty = null;
                BaseControlHandler.HandleControl(frameworkElement, propertyInfo, dataCategory, dataProperty, ref dependencyProperty);
                HandleControl(frameworkElement, propertyInfo, dataCategory, dataProperty, ref dependencyProperty);
                dataContentCache.AddElement(frameworkElement, dependencyProperty, propertyInfo);
            }

            return(dataContentCache);
        }