Exemple #1
0
        private IEnumerable <PropertyItem> CollectProperties(IList <object> components)
        {
            if (components == null || components.Count == 0)
            {
                throw new ArgumentNullException("components");
            }

            // This is an obsolete code left for performance improvements demo. Will be removed in the future versions.

            /*
             * var descriptors = component.Length == 1
             * ? TypeDescriptor.GetProperties(component[0], DefaultPropertiesFilter).OfType<PropertyDescriptor>()
             * : ObjectServices.GetMergedProperties(component);
             */

            // TODO: PropertyItem is to be wired with PropertyData rather than pure PropertyDescriptor in the next version!
            var descriptors = (components.Count == 1)
              ? MetadataRepository.GetProperties(components[0]).Select(prop => prop.Descriptor)
              : ObjectServices.GetMergedProperties(components);

            IList <PropertyItem> propertyCollection = new List <PropertyItem>();

            foreach (var propertyDescriptor in descriptors)
            // This is an obsolete code left for performance improvements demo. Will be removed in the future versions.
            //CollectProperties(component, propertyDescriptor, propertyCollection);
            {
                var item = CreatePropertyItem(propertyDescriptor);
                if (item != null)
                {
                    propertyCollection.Add(item);
                }
            }

            return(propertyCollection);
        }
Exemple #2
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));
        }
Exemple #3
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);
        }
 /// <summary>
 /// Gets the serialization culture.
 /// </summary>
 /// <returns>Culture to serialize value.</returns>
 protected virtual CultureInfo GetSerializationCulture()
 {
   return ObjectServices.GetSerializationCulture(_property.PropertyType);
 }