Exemplo n.º 1
0
        public void TryCreateInheritedEditor()
        {
            Assert.IsInstanceOf <Iface1Editor>(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(Iface1Editor)));
            Assert.IsInstanceOf <Iface1Editor <int> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int>), typeof(Iface1Editor <>)));
            Assert.IsInstanceOf <Iface1Editor <int, object> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object>), typeof(Iface1Editor <,>)));
            Assert.IsInstanceOf <Iface1Editor <int, object, string> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object, string>), typeof(Iface1Editor <, ,>)));

            Assert.IsNull(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(Iface1Editor <>)));
            Assert.IsNotNull(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(Iface1EditorIncludeType <>)));

            Assert.IsInstanceOf <Iface1EditorIncludeType <Data> >(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(Iface1EditorIncludeType <>)));
            Assert.IsInstanceOf <Iface1EditorIncludeType <Data <int>, int> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int>), typeof(Iface1EditorIncludeType <,>)));
            Assert.IsInstanceOf <Iface1EditorIncludeType <Data <int, object>, int, object> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object>), typeof(Iface1EditorIncludeType <, ,>)));
            Assert.IsInstanceOf <Iface1EditorIncludeType <Data <int, object, string>, int, object, string> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object, string>), typeof(Iface1EditorIncludeType <, , ,>)));

            Assert.IsInstanceOf <Iface2Editor>(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(Iface2Editor)));
            Assert.IsInstanceOf <Iface2Editor <int> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int>), typeof(Iface2Editor <>)));
            Assert.IsInstanceOf <Iface2Editor <int, object> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object>), typeof(Iface2Editor <,>)));
            Assert.IsInstanceOf <Iface2Editor <int, object, string> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object, string>), typeof(Iface2Editor <, ,>)));

            Assert.IsInstanceOf <Iface2EditorIncludeType <Data> >(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(Iface2EditorIncludeType <>)));
            Assert.IsInstanceOf <Iface2EditorIncludeType <Data <int>, int> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int>), typeof(Iface2EditorIncludeType <,>)));
            Assert.IsInstanceOf <Iface2EditorIncludeType <Data <int, object>, int, object> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object>), typeof(Iface2EditorIncludeType <, ,>)));
            Assert.IsInstanceOf <Iface2EditorIncludeType <Data <int, object, string>, int, object, string> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object, string>), typeof(Iface2EditorIncludeType <, , ,>)));
        }
Exemplo n.º 2
0
        public void ListEditorTest()
        {
            Assert.IsInstanceOf <IListEditor <CustomList, int> >(PropertyEditorTools.TryCreateEditor(typeof(CustomList), typeof(IListPropertyEditor <,>)));
            Assert.IsInstanceOf <IListEditor <List <int>, int> >(PropertyEditorTools.TryCreateEditor(typeof(List <int>), typeof(IListEditor <,>)));
            Assert.IsNull(PropertyEditorTools.TryCreateEditor(typeof(int), typeof(IListEditor <,>)));

            Assert.IsInstanceOf <IListEditor <List <CustomList>, CustomList> >(PropertyEditorTools.TryCreateEditor(typeof(List <CustomList>), typeof(IListEditor <,>)));
            Assert.IsInstanceOf <IListEditor <List <List <int> >, List <int> > >(PropertyEditorTools.TryCreateEditor(typeof(List <List <int> >), typeof(IListEditor <,>)));
        }
Exemplo n.º 3
0
        public void TryCreateEditorTest()
        {
            Assert.IsInstanceOf <DataEditor>(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(DataEditor)));
            Assert.IsInstanceOf <DataEditor <int> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int>), typeof(DataEditor <>)));
            Assert.IsInstanceOf <DataEditor <int, object> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object>), typeof(DataEditor <,>)));
            Assert.IsInstanceOf <DataEditor <int, object, string> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object, string>), typeof(DataEditor <, ,>)));

            Assert.IsInstanceOf <DataEditorIncludeType <Data> >(PropertyEditorTools.TryCreateEditor(typeof(Data), typeof(DataEditorIncludeType <>)));
            Assert.IsInstanceOf <DataEditorIncludeType <Data <int>, int> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int>), typeof(DataEditorIncludeType <,>)));
            Assert.IsInstanceOf <DataEditorIncludeType <Data <int, object>, int, object> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object>), typeof(DataEditorIncludeType <, ,>)));
            Assert.IsInstanceOf <DataEditorIncludeType <Data <int, object, string>, int, object, string> >(PropertyEditorTools.TryCreateEditor(typeof(Data <int, object, string>), typeof(DataEditorIncludeType <, , ,>)));
        }
Exemplo n.º 4
0
 public void ObjectEditorTest()
 {
     Assert.IsInstanceOf <ObjectEditor>(PropertyEditorTools.TryCreateEditor(typeof(object), typeof(ObjectEditor)));
     Assert.IsNull(PropertyEditorTools.TryCreateEditor(typeof(int), typeof(ObjectEditor)));
 }
Exemplo n.º 5
0
        /// <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);
        }