/// <summary> /// Intantiates a new instance of <see cref="Property"/>. /// </summary> /// <param name="serviceProvider">The <see cref="IServiceProvider"/> used to obtain services. This is most-often used when the property appears in an editor.</param> /// <param name="component">The <see cref="object"/> that contains the property described by <paramref name="declaringProperty"/>.</param> /// <param name="declaringProperty">The description of the property owned by <paramref name="component"/>.</param> /// <param name="additionalAttributes">Additional, or overridden, meta-data attributes for the <paramref name="declaringProperty"/></param> public Property(IServiceProvider serviceProvider, object component, PropertyDescriptor declaringProperty, IEnumerable<Attribute> additionalAttributes) { this.serviceProvider = serviceProvider; this.component = component; this.declaringProperty = declaringProperty; if (declaringProperty != null) { metadata = new MetadataCollection(declaringProperty.Attributes.OfType<Attribute>()); metadata.Override(additionalAttributes); } else { metadata = new MetadataCollection(additionalAttributes); } Initialize(declaringProperty, metadata.Attributes); }
/// <summary> /// Creates a new set of <see cref="Attribute"/> instances using <see cref="MetadataCollection"/> to /// combine a base set and <see cref="Attribute"/> instances and an override set of <see cref="Attribute"/> instances. /// </summary> /// <param name="baseSource">The base set of attributes that may be overridden.</param> /// <param name="overriddenSource">The overrideent set of attributes.</param> /// <returns>The resultant set of <see cref="Attribute"/> instances with overridden values applied.</returns> public static IEnumerable<Attribute> CombineAttributes(IEnumerable<Attribute> baseSource, IEnumerable<Attribute> overriddenSource) { MetadataCollection collection = new MetadataCollection(baseSource); collection.Override(overriddenSource); return collection.Attributes; }