public object Lookup(Type type) { if (type == typeof(IOptionGroup)) { return(parentGroup); } else { return(parent.Lookup(type)); } }
internal ChildBuilderContext(IOptionBuilderContext context, string prefix, string groupName, ISelectionProvider <T> selectionProvider) { IOptionGroup group = context.Lookup <IOptionGroup>(); if (group != null && groupName != string.Empty) { group.Items.Add(this.parentGroup = new OptionGroup(groupName)); } else { this.parentGroup = group; } this.parent = context; this.propertyPrefix = CreatePrefix(prefix, groupName); this.selectionProvider = selectionProvider; }
/// <inheritdoc/> public void AddItems(IOptionBuilderContext context, Type subjectType, object subject) { Type type1 = subject == null?subjectType:subject.GetType(); PropertyInfo[] propertyInfos = SortProperties(FilterProperties( type1.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy), context), context); foreach (PropertyInfo descriptor in propertyInfos) { DisplayNameAttribute displayNameAttribute = GetAttribute <DisplayNameAttribute>(descriptor); string propertyName; if (displayNameAttribute == null || displayNameAttribute.DisplayName.Length < 1) { propertyName = descriptor.Name; } else { propertyName = displayNameAttribute.DisplayName; } Type type = descriptor.PropertyType; object value = descriptor.GetGetMethod().Invoke(subject, null); IOptionBuilder builder = GetBuilder(descriptor, context, subject, type); if (builder != null) { IOptionBuilderContext childContext = context.CreateChildContext(propertyName); builder.AddItems(childContext, type, value); ConfigureItem(childContext.Lookup <IOptionGroup>(), descriptor); } else { IOptionItem item = CreateItem(context, descriptor, type, propertyName, value); if (item != null) { context.BindItem(item, propertyName); ConfigureItem(item, descriptor); } } } }
/// <inheritdoc/> public virtual void AddItems(IOptionBuilderContext context, Type subjectType, object subject) { DefaultBrushOptionBuilder brushOptionBuilder = new DefaultBrushOptionBuilder(); brushOptionBuilder.AllowNullValue = AllowNullValue; brushOptionBuilder.AddItems(context, typeof(Brush), null); FloatOptionItem widthItem = new FloatOptionItem(DefaultPenPropertyMapBuilder.Width); bool widthItemAdded = context.BindItem(widthItem, DefaultPenPropertyMapBuilder.Width); GenericOptionItem <DashStyle> dashStyleItem = new GenericOptionItem <DashStyle>(DefaultPenPropertyMapBuilder.DashStyle, OptionItem.VALUE_UNDEFINED); dashStyleItem.SetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE, true); dashStyleItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); // dashStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, typeof(PenDashStyleUITypeEditor)); EnumUITypeEditor <DashStyle> editor = new EnumUITypeEditor <DashStyle>(); editor.Renderer = new DashStyleItemRenderer(); dashStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, editor); // dashStyleItem.SetAttribute(OptionItem.CUSTOM_CELLRENDERER, typeof(DashStyleItemRenderer)); bool dashStyleItemAdded = context.BindItem(dashStyleItem, DefaultPenPropertyMapBuilder.DashStyle); IOptionGroup parent = context.Lookup <IOptionGroup>(); if (parent != null) { IOptionItem fillTypeItem = parent[DefaultBrushPropertyMapBuilder.FillType]; ConstraintManager cm = parent.Lookup <ConstraintManager>(); if (cm != null && fillTypeItem != null) { ICondition cond = ConstraintManager.LogicalCondition.Not(cm.CreateValueEqualsCondition(fillTypeItem, null)); if (widthItemAdded) { cm.SetEnabledOnCondition(cond, widthItem); } if (dashStyleItemAdded) { cm.SetEnabledOnCondition(cond, dashStyleItem); } } } }
/// <inheritdoc/> public void AddItems(IOptionBuilderContext context, Type subjectType, object subject) { PropertyInfo[] propertyInfos = SortProperties(context, FilterProperties(context, subjectType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))); foreach (PropertyInfo info in propertyInfos) { DisplayAttribute descriptionAttribute = GetAttribute <DisplayAttribute>(info); #if UseDataAnnotations string description = descriptionAttribute == null ? info.Name : descriptionAttribute.GetName(); #else string description = descriptionAttribute == null ? info.Name : descriptionAttribute.DisplayName; #endif object value = subject == null ? null : info.GetValue(subject, null); Type type = value == null ? info.PropertyType : value.GetType(); IOptionBuilder builder = GetBuilder(context, info, subject, type); if (builder != null) { IOptionBuilderContext childContext = context.CreateChildContext(description); builder.AddItems(childContext, type, value); ConfigureItem((IOptionItem)childContext.Lookup(typeof(IOptionGroup)), info); } else { IOptionItem item = CreateItem(context, info, type, description, value); if (item != null) { context.BindItem(item, description); ConfigureItem(item, info); } } } }
/// <inheritdoc/> public virtual void AddItems(IOptionBuilderContext context, Type subjectType, object subject) { // CollectionOptionItem<string> fillTypeItem = // new CollectionOptionItem<string>(DefaultBrushPropertyMapBuilder.FillType, // new string[] { // DefaultBrushPropertyMapBuilder.SolidBrushFillType, // DefaultBrushPropertyMapBuilder.HatchBrushFillType, // DefaultBrushPropertyMapBuilder.LinearGradientBrushFillType, // DefaultBrushPropertyMapBuilder.TextureBrushFillType // }); GenericOptionItem <BrushTypes> fillTypeItem = new GenericOptionItem <BrushTypes>(DefaultBrushPropertyMapBuilder.FillType); fillTypeItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, AllowNullValue); // fillTypeItem.SetAttribute(OptionItem.NULL_VALUE_OBJECT, BrushTypes.Nothing); fillTypeItem.SetAttribute(OptionItem.NULL_VALUE_STRING_ATTRIBUTE, "Nothing"); bool fillTypeAdded = context.BindItem(fillTypeItem, DefaultBrushPropertyMapBuilder.FillType ); ColorOptionItem foreColorItem = new ColorOptionItem(DefaultBrushPropertyMapBuilder.ForegroundColor); bool foreColorAdded = context.BindItem(foreColorItem, DefaultBrushPropertyMapBuilder.ForegroundColor); ColorOptionItem backColorOptionItem = new ColorOptionItem(DefaultBrushPropertyMapBuilder.BackgroundColor); bool backColorAdded = context.BindItem(backColorOptionItem, DefaultBrushPropertyMapBuilder.BackgroundColor); GenericOptionItem <HatchStyle> hatchStyleItem = new GenericOptionItem <HatchStyle>(DefaultBrushPropertyMapBuilder.HatchStyle, OptionItem.VALUE_UNDEFINED); hatchStyleItem.SetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE, true); hatchStyleItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); bool hatchItemAdded = context.BindItem(hatchStyleItem, DefaultBrushPropertyMapBuilder.HatchStyle); if (hatchItemAdded) { EnumUITypeEditor <HatchStyle> hatchEditor = new EnumUITypeEditor <HatchStyle>(); hatchEditor.Renderer = new HatchStyleItemRenderer(); hatchStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, hatchEditor); } FloatOptionItem rotationItem = new FloatOptionItem(DefaultBrushPropertyMapBuilder.Rotation); bool floatItemAdded = context.BindItem(rotationItem, DefaultBrushPropertyMapBuilder.Rotation); GenericOptionItem <Image> imageItem = new GenericOptionItem <Image>(DefaultBrushPropertyMapBuilder.Image, OptionItem.VALUE_UNDEFINED); imageItem.SetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE, true); imageItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); bool imageItemAdded = context.BindItem(imageItem, DefaultBrushPropertyMapBuilder.Image); if (fillTypeAdded) { ConstraintManager cm = context.Lookup <ConstraintManager>(); if (cm != null) { if (foreColorAdded) { ICondition cond = cm.CreateValueIsOneOfCondition(fillTypeItem, BrushTypes.SolidBrush, BrushTypes.HatchBrush, BrushTypes.LinearGradientBrush); cm.SetEnabledOnCondition(cond, foreColorItem); } if (backColorAdded) { ICondition cond = cm.CreateValueIsOneOfCondition(fillTypeItem, BrushTypes.HatchBrush, BrushTypes.LinearGradientBrush); cm.SetEnabledOnCondition(cond, backColorOptionItem); } if (hatchItemAdded) { cm.SetEnabledOnValueEquals(fillTypeItem, BrushTypes.HatchBrush, hatchStyleItem); } if (imageItemAdded) { cm.SetEnabledOnValueEquals(fillTypeItem, BrushTypes.TextureBrush, imageItem); } if (floatItemAdded) { cm.SetEnabledOnValueEquals(fillTypeItem, BrushTypes.LinearGradientBrush, rotationItem); } } } }