コード例 #1
0
        /// <summary>
        /// Gets the editor.
        /// </summary>
        /// <param name="categoryItem">The category item.</param>
        /// <returns>Editor for Category</returns>
        public Editor GetEditor(CategoryItem categoryItem)
        {
            if (categoryItem == null)
            {
                throw new ArgumentNullException("categoryItem");
            }

            if (categoryItem.Owner == null)
            {
                return(null);
            }

            object declaringObject = ObjectServices.GetUnwrappedObject(categoryItem.Owner.SelectedObject);

            if (declaringObject == null)
            {
                return(null);
            }

            Type declaringType = declaringObject.GetType();

            Editor editor = FindCategoryEditor(declaringType, categoryItem.Name);

            if (editor != null)
            {
                return(editor);
            }

            editor = GetCategoryEditorByAttributes(declaringType, categoryItem.Name);
            if (editor != null)
            {
                return(editor);
            }

            return(new CategoryEditor(declaringType, categoryItem.Name, EditorKeys.DefaultCategoryEditorKey));
        }
コード例 #2
0
        /// <summary>
        /// Gets the editor.
        /// </summary>
        /// <param name="propertyItem">The property item.</param>
        /// <returns>Editor for Property</returns>
        public Editor GetEditor(PropertyItem propertyItem)
        {
            if (propertyItem == null)
            {
                throw new ArgumentNullException("propertyItem");
            }

            Editor editor;

            if (propertyItem.Attributes != null)
            {
                editor = GetPropertyEditorByAttributes(propertyItem.Attributes);
                if (editor != null)
                {
                    return(editor);
                }
            }

            if (propertyItem.Component != null && !string.IsNullOrEmpty(propertyItem.Name))
            {
                object declaringObject = ObjectServices.GetUnwrappedObject(propertyItem.Owner.SelectedObject);
                editor = FindPropertyEditor(declaringObject.GetType(), propertyItem.Name);
                if (editor != null)
                {
                    return(editor);
                }
            }

            bool hasType = propertyItem.PropertyType != null;

            var context = new TypeDescriptorContext(propertyItem);
            var hasExclusiveStandardValues = propertyItem.Converter.GetStandardValuesExclusive(context);

            if (hasType)
            {
                editor = FindTypeEditor(propertyItem.PropertyType);
                if (editor != null)
                {
                    return(editor);
                }
            }

            if (propertyItem.PropertyValue.HasSubProperties)
            {
                if (hasExclusiveStandardValues)
                {
                    var standardValues = propertyItem.Converter.GetStandardValues(context);
                    return(new TypeEditor(propertyItem.PropertyType, EditorKeys.ComplexPropertyEnumEditorKey));
                }

                return(new TypeEditor(propertyItem.PropertyType, EditorKeys.ComplexPropertyEditorKey));
            }

            if (hasType)
            {
                foreach (var cachedEditor in Cache)
                {
                    if (cachedEditor.Key.IsAssignableFrom(propertyItem.PropertyType))
                    {
                        return(cachedEditor.Value);
                    }
                }

                if (hasExclusiveStandardValues)
                {
                    try
                    {
                        var standardValues = propertyItem.Converter.GetStandardValues(context);
                        return(new TypeEditor(propertyItem.PropertyType, EditorKeys.EnumEditorKey));
                    }
                    catch (NotImplementedException)
                    {
                        /* failed to get standardValues. Not an Enum? */
                    }
                }

                return(new TypeEditor(propertyItem.PropertyType, EditorKeys.DefaultEditorKey));
            }

            return(null);
        }