示例#1
0
        /// <summary>
        /// Creates a <see cref="PropertyFilterConfigurationAdapter"/>.
        /// Constructor parameters correspond to the configuration schema.
        /// </summary>
        /// <param name="declaringType">Filters properties by applying a filter to their declaring type.</param>
        /// <param name="propertyType">Filters properties by applying a filter to the type of the property.</param>
        /// <param name="hasAttribute">Filters properties to those that are decorated with one of the specified attributes.</param>
        public PropertyFilterConfigurationAdapter(TypeFilterConfigurationAdapter declaringType, TypeFilterConfigurationAdapter propertyType, IEnumerable <string> hasAttribute)
        {
            var filters = new List <IFilter <PropertyInfo> >();

            if (declaringType != null)
            {
                filters.Add(ProjectedFilter.Create(declaringType, (PropertyInfo p) => p.DeclaringType));
            }
            if (propertyType != null)
            {
                filters.Add(ProjectedFilter.Create(propertyType, (PropertyInfo p) => p.PropertyType));
            }
            if (hasAttribute != null)
            {
                filters.Add(new HasAttributeFilter(hasAttribute));
            }

            // Multiple filters in a single adapter must all be fulfilled for a match.
            _filter = CompositeFilter.And(filters);
        }
        /// <summary>
        /// Creates a <see cref="TypeFilterConfigurationAdapter"/>.
        /// Constructor parameters correspond to the configuration schema.
        /// </summary>
        /// <param name="hasAttribute">Filters types to those that are decorated with one of the specified attributes.</param>
        /// <param name="subTypeOf">Filters types to those that are subtypes of one of the specified types.</param>
        /// <param name="namespace">Filters types to those that are declared in the specified namespace.</param>
        /// <param name="isEnum">True, if only types should be matched that represent an enum type.</param>
        public TypeFilterConfigurationAdapter(IEnumerable <string> hasAttribute, IEnumerable <string> subTypeOf, string @namespace, bool isEnum)
        {
            var filters = new List <IFilter <Type> >();

            if (hasAttribute != null)
            {
                filters.Add(new HasAttributeFilter(hasAttribute));
            }
            if (subTypeOf != null)
            {
                filters.Add(new SubTypeFilter(subTypeOf));
            }
            if (@namespace != null)
            {
                filters.Add(new NamespaceFilter(@namespace));
            }
            if (isEnum)
            {
                filters.Add(new IsEnumFilter());
            }

            // Multiple filters in a single adapter must all be fulfilled for a match.
            _filter = CompositeFilter.And(filters);
        }