private static PropertyEditorChain GetCachedEditors(Type propertyType, ICustomAttributeProvider attributes) { PropertyEditor.CachedType key = new PropertyEditor.CachedType { EditedType = propertyType, EditedAttributes = attributes }; PropertyEditorChain propertyEditorChain; if (!PropertyEditor._cachedPropertyEditors.TryGetValue(key, out propertyEditorChain)) { propertyEditorChain = new PropertyEditorChain(); PropertyEditor._cachedPropertyEditors[key] = propertyEditorChain; IPropertyEditor propertyEditor; if ((propertyEditor = AttributePropertyEditor.TryCreate(propertyType, attributes)) != null) { propertyEditorChain.AddEditor(propertyEditor); } if ((propertyEditor = ArrayPropertyEditor.TryCreate(propertyType)) != null) { propertyEditorChain.AddEditor(propertyEditor); } List<IPropertyEditor> list = new List<IPropertyEditor>(); foreach (Type current in PropertyEditor._editorTypes) { propertyEditor = PropertyEditorTools.TryCreateEditor(propertyType, current); if (propertyEditor != null) { list.Add(propertyEditor); } } PropertyEditor.SortByPropertyTypeRelevance(list); foreach (IPropertyEditor current2 in list) { propertyEditorChain.AddEditor(current2); } if ((propertyEditor = EnumPropertyEditor.TryCreate(propertyType)) != null) { propertyEditorChain.AddEditor(propertyEditor); } if ((propertyEditor = NullablePropertyEditor.TryCreate(propertyType)) != null) { propertyEditorChain.AddEditor(propertyEditor); } if ((propertyEditor = AbstractTypePropertyEditor.TryCreate(propertyType)) != null) { propertyEditorChain.AddEditor(propertyEditor); } if ((propertyEditor = ReflectedPropertyEditor.TryCreate(propertyType)) != null) { propertyEditorChain.AddEditor(propertyEditor); } } return propertyEditorChain; }
/// <summary> /// Returns a set of property editors that can be used to edit the given property type. /// </summary> private static PropertyEditorChain GetCachedEditors(Type propertyType, ICustomAttributeProvider attributes) { var cachedType = new CachedType { EditedType = propertyType, EditedAttributes = attributes }; PropertyEditorChain chain; if (_cachedPropertyEditors.TryGetValue(cachedType, out chain) == false) { chain = new PropertyEditorChain(); _cachedPropertyEditors[cachedType] = chain; IPropertyEditor editor; if ((editor = AttributePropertyEditor.TryCreate(propertyType, attributes)) != null) { chain.AddEditor(editor); } // arrays always need special handling; we don't support overriding them if ((editor = ArrayPropertyEditor.TryCreate(propertyType, attributes)) != null) { chain.AddEditor(editor); } // support layout editors above custom editors // notably this enables the layout editor to be the highest-priority, ie, above inherited editors if ((editor = tkControlPropertyEditor.TryCreate(propertyType, attributes)) != null) { chain.AddEditor(editor); } // user-defined property editors var added = new List <IPropertyEditor>(); foreach (Type editorType in _editorTypes) { editor = PropertyEditorTools.TryCreateEditor(propertyType, editorType, attributes, false); if (editor != null) { added.Add(editor); } } SortByPropertyTypeRelevance(added); foreach (IPropertyEditor toAdd in added) { chain.AddEditor(toAdd); } // no user-defined editors so let's try to see if we can integrate a PropertyDrawer if (added.Count == 0) { if ((editor = fiGenericPropertyDrawerPropertyEditorManager.TryCreate(propertyType)) != null) { chain.AddEditor(editor); } } // enums come after generic & inherited to allow them to be overridden if ((editor = EnumPropertyEditor.TryCreate(propertyType)) != null) { chain.AddEditor(editor); } // try and create an editor for nullable types if ((editor = NullablePropertyEditor.TryCreate(propertyType, attributes)) != null) { chain.AddEditor(editor); } // try and create an editor for abstract/interface type if ((editor = AbstractTypePropertyEditor.TryCreate(propertyType)) != null) { chain.AddEditor(editor); } // try and create a reflected editor; will only fail for arrays or collections, // which should be covered by the array editor if ((editor = ReflectedPropertyEditor.TryCreate(propertyType, attributes)) != null) { chain.AddEditor(editor); } } return(chain); }