public override void ConfigureEditor(PropertyEditor editor, object configureData = null) { IEnumerable <EditorHintAttribute> hintOverride = configureData as IEnumerable <EditorHintAttribute>; IEnumerable <EditorHintAttribute> parentHint = null; if (editor.ParentEditor != null) { IEnumerable <EditorHintAttribute> parentHintOverride = editor.ParentEditor.ConfigureData as IEnumerable <EditorHintAttribute>; if (editor.ParentEditor.EditedMember != null) { parentHint = EditorHintAttribute.GetAll <EditorHintAttribute>(editor.ParentEditor.EditedMember, parentHintOverride); } else { parentHint = parentHintOverride; } } if (hintOverride == null && parentHint != null) { // No configuration data available? Allow to derive certain types from parent list or dictionary. if (editor.ParentEditor is IListPropertyEditor || editor.ParentEditor is IDictionaryPropertyEditor) { hintOverride = parentHint.Where(a => a is EditorHintDecimalPlacesAttribute || a is EditorHintIncrementAttribute || a is EditorHintRangeAttribute); } // That way we can specify the decimal places of an array of Vector2-structs and actually change those Vector2 editors. } // Invoke the PropertyEditor's configure method base.ConfigureEditor(editor, hintOverride); // Do some final configuration for editors that do not behave as intended by default. if (editor is MemberwisePropertyEditor) { MemberwisePropertyEditor memberEditor = editor as MemberwisePropertyEditor; memberEditor.MemberPredicate = this.EditorMemberPredicate; memberEditor.MemberAffectsOthers = this.EditorMemberAffectsOthers; memberEditor.MemberPropertySetter = this.EditorMemberPropertySetter; memberEditor.MemberFieldSetter = this.EditorMemberFieldSetter; } if (editor is IListPropertyEditor) { IListPropertyEditor listEditor = editor as IListPropertyEditor; listEditor.ListIndexSetter = this.EditorListIndexSetter; } if (editor is IDictionaryPropertyEditor) { IDictionaryPropertyEditor dictEditor = editor as IDictionaryPropertyEditor; dictEditor.DictionaryKeySetter = this.EditorDictionaryKeySetter; } var flagsAttrib = EditorHintAttribute.Get <EditorHintFlagsAttribute>(editor.EditedMember, hintOverride); if (flagsAttrib != null) { editor.ForceWriteBack = (flagsAttrib.Flags & MemberFlags.ForceWriteback) == MemberFlags.ForceWriteback; if ((flagsAttrib.Flags & MemberFlags.ReadOnly) == MemberFlags.ReadOnly) { editor.Setter = null; } } if (editor is NumericPropertyEditor) { var rangeAttrib = EditorHintAttribute.Get <EditorHintRangeAttribute>(editor.EditedMember, hintOverride); var incAttrib = EditorHintAttribute.Get <EditorHintIncrementAttribute>(editor.EditedMember, hintOverride); var placesAttrib = EditorHintAttribute.Get <EditorHintDecimalPlacesAttribute>(editor.EditedMember, hintOverride); NumericPropertyEditor numEditor = editor as NumericPropertyEditor; if (rangeAttrib != null) { numEditor.ValueBarMaximum = rangeAttrib.ReasonableMaximum; numEditor.ValueBarMinimum = rangeAttrib.ReasonableMinimum; numEditor.Maximum = rangeAttrib.LimitMaximum; numEditor.Minimum = rangeAttrib.LimitMinimum; } if (incAttrib != null) { numEditor.Increment = incAttrib.Increment; } if (placesAttrib != null) { numEditor.DecimalPlaces = placesAttrib.Places; } } }
public PropertyEditor CreateEditor(Type baseType, ProviderContext context) { PropertyEditor e = null; // Basic numeric data types if (baseType == typeof(sbyte) || baseType == typeof(byte) || baseType == typeof(short) || baseType == typeof(ushort) || baseType == typeof(int) || baseType == typeof(uint) || baseType == typeof(long) || baseType == typeof(ulong) || baseType == typeof(float) || baseType == typeof(double) || baseType == typeof(decimal)) e = new NumericPropertyEditor(); // Basic data type: Boolean else if (baseType == typeof(bool)) e = new BoolPropertyEditor(); // Basic data type: Flagged Enum else if (baseType.IsEnum && baseType.GetCustomAttributes(typeof(FlagsAttribute), true).Any()) e = new FlaggedEnumPropertyEditor(); // Basic data type: Other Enums else if (baseType.IsEnum) e = new EnumPropertyEditor(); // Basic data type: String else if (baseType == typeof(string)) e = new StringPropertyEditor(); // IList else if (typeof(System.Collections.IList).IsAssignableFrom(baseType)) e = new IListPropertyEditor(); // IList else if (typeof(System.Collections.IDictionary).IsAssignableFrom(baseType)) e = new IDictionaryPropertyEditor(); // Unknown data type else { // Ask around if any sub-editor can handle it and choose the most specialized var availSubProviders = from p in this.subProviders where p.IsResponsibleFor(baseType, context) != EditorPriority_None orderby p.IsResponsibleFor(baseType, context) descending select p; IPropertyEditorProvider subProvider = availSubProviders.FirstOrDefault(); if (subProvider != null) { e = subProvider.CreateEditor(baseType, context); e.EditedType = baseType; return e; } // If not, default to reflection-driven MemberwisePropertyEditor e = new MemberwisePropertyEditor(); } e.EditedType = baseType; return e; }
public PropertyEditor CreateEditor(Type baseType, ProviderContext context) { PropertyEditor e = null; // Basic numeric data types if (baseType == typeof(sbyte) || baseType == typeof(byte) || baseType == typeof(short) || baseType == typeof(ushort) || baseType == typeof(int) || baseType == typeof(uint) || baseType == typeof(long) || baseType == typeof(ulong) || baseType == typeof(float) || baseType == typeof(double) || baseType == typeof(decimal)) { e = new NumericPropertyEditor(); } // Basic data type: Boolean else if (baseType == typeof(bool)) { e = new BoolPropertyEditor(); } // Basic data type: Flagged Enum else if (baseType.IsEnum && baseType.GetCustomAttributes(typeof(FlagsAttribute), true).Any()) { e = new FlaggedEnumPropertyEditor(); } // Basic data type: Other Enums else if (baseType.IsEnum) { e = new EnumPropertyEditor(); } // Basic data type: String else if (baseType == typeof(string)) { e = new StringPropertyEditor(); } // IList else if (typeof(System.Collections.IList).IsAssignableFrom(baseType)) { e = new IListPropertyEditor(); } // IList else if (typeof(System.Collections.IDictionary).IsAssignableFrom(baseType)) { e = new IDictionaryPropertyEditor(); } // Unknown data type else { // Ask around if any sub-editor can handle it and choose the most specialized var availSubProviders = from p in this.subProviders where p.IsResponsibleFor(baseType, context) != EditorPriority_None orderby p.IsResponsibleFor(baseType, context) descending select p; IPropertyEditorProvider subProvider = availSubProviders.FirstOrDefault(); if (subProvider != null) { e = subProvider.CreateEditor(baseType, context); e.EditedType = baseType; return(e); } // If not, default to reflection-driven MemberwisePropertyEditor e = new MemberwisePropertyEditor(); } e.EditedType = baseType; return(e); }