Exemplo n.º 1
0
        /// <summary>
        /// Define a rule that will apply to the types <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The type to which the rule applies.</typeparam>
        /// <returns>A <see cref="PartConventionBuilder{T}"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder <T> ForType <T>()
        {
            var partBuilder = new PartConventionBuilder <T>((t) => t == typeof(T));

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Define a rule that will apply to all types that
        /// derive from (or implement) the specified type.
        /// </summary>
        /// <typeparam name="T">The type from which matching types derive.</typeparam>
        /// <returns>A <see cref="PartConventionBuilder{T}"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder <T> ForTypesDerivedFrom <T>()
        {
            var partBuilder = new PartConventionBuilder <T>((t) => IsDescendentOf(t, typeof(T)));

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 3
0
        private IEnumerable <Tuple <object, List <Attribute> > > EvaluateThisTypeInfoAgainstTheConvention(TypeInfo typeInfo)
        {
            List <Tuple <object, List <Attribute> > > results = new List <Tuple <object, List <Attribute> > >();
            List <Attribute> attributes = new List <Attribute>();
            var  configuredMembers      = new List <Tuple <object, List <Attribute> > >();
            bool specifiedConstructor   = false;
            bool matchedConvention      = false;
            var  type = typeInfo.AsType();

            foreach (var builder in _conventions.Where(c => c.SelectType(type)))
            {
                attributes.AddRange(builder.BuildTypeAttributes(type));

                specifiedConstructor |= builder.BuildConstructorAttributes(type, ref configuredMembers);
                builder.BuildPropertyAttributes(type, ref configuredMembers);
                builder.BuildOnImportsSatisfiedNotification(type, ref configuredMembers);

                matchedConvention = true;
            }
            if (matchedConvention && !specifiedConstructor)
            {
                // DefaultConstructor
                PartConventionBuilder.BuildDefaultConstructorAttributes(type, ref configuredMembers);
            }
            configuredMembers.Add(Tuple.Create((object)type.GetTypeInfo(), attributes));
            return(configuredMembers);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Define a rule that will apply to types assignable to <typeparamref name="T"/> that
        /// match the supplied predicate.
        /// </summary>
        /// <param name="typeFilter">A predicate that selects matching types.</param>
        /// <typeparam name="T">The type to which the rule applies.</typeparam>
        /// <returns>A <see cref="PartConventionBuilder{T}"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder <T> ForTypesMatching <T>(Predicate <Type> typeFilter)
        {
            Requires.NotNull(typeFilter, "typeFilter");

            var partBuilder = new PartConventionBuilder <T>(typeFilter);

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Define a rule that will apply to the types <paramref name="type"/>.
        /// </summary>
        /// <param name="type">The type to which the rule applies.</param>
        /// <returns>A <see cref="PartConventionBuilder"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder ForType(Type type)
        {
            Requires.NotNull(type, "type");

            var partBuilder = new PartConventionBuilder((t) => t == type);

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Define a rule that will apply to all types that
        /// derive from (or implement) the specified type.
        /// </summary>
        /// <param name="type">The type from which matching types derive.</param>
        /// <returns>A <see cref="PartConventionBuilder"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder ForTypesDerivedFrom(Type type)
        {
            Requires.NotNull(type, "type");

            var partBuilder = new PartConventionBuilder((t) => IsDescendentOf(t, type));

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Define a rule that will apply to types that
        /// match the supplied predicate.
        /// </summary>
        /// <param name="typeFilter">A predicate that selects matching types.</param>
        /// <returns>A <see cref="PartConventionBuilder{T}"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder ForTypesMatching(Predicate <Type> typeFilter)
        {
            Requires.NotNull(typeFilter, nameof(typeFilter));

            var partBuilder = new PartConventionBuilder(typeFilter);

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Define a rule that will apply to types assignable to <typeparamref name="T"/> that
        /// match the supplied predicate.
        /// </summary>
        /// <param name="typeFilter">A predicate that selects matching types.</param>
        /// <typeparam name="T">The type to which the rule applies.</typeparam>
        /// <returns>A <see cref="PartConventionBuilder{T}"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder <T> ForTypesMatching <T>(Predicate <Type> typeFilter)
        {
            if (typeFilter == null)
            {
                throw new ArgumentNullException(nameof(typeFilter));
            }

            var partBuilder = new PartConventionBuilder <T>(typeFilter);

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Define a rule that will apply to the types <paramref name="type"/>.
        /// </summary>
        /// <param name="type">The type to which the rule applies.</param>
        /// <returns>A <see cref="PartConventionBuilder"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder ForType(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var partBuilder = new PartConventionBuilder((t) => t == type);

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Define a rule that will apply to all types that
        /// derive from (or implement) the specified type.
        /// </summary>
        /// <param name="type">The type from which matching types derive.</param>
        /// <returns>A <see cref="PartConventionBuilder"/> that must be used to specify the rule.</returns>
        public PartConventionBuilder ForTypesDerivedFrom(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var partBuilder = new PartConventionBuilder((t) => IsDescendentOf(t, type));

            _conventions.Add(partBuilder);
            return(partBuilder);
        }
Exemplo n.º 11
0
 public static PartConventionBuilder ExportInterfaces(this PartConventionBuilder pb)
 {
     return(null);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Configure the part to use constructor with most parameters
 /// </summary>
 /// <param name="partConventionBuilder"></param>
 /// <returns></returns>
 public static PartConventionBuilder SelectConstructorWithMostParameters(this PartConventionBuilder partConventionBuilder)
 {
     return(partConventionBuilder.SelectConstructor((constructors) => constructors.OrderByDescending(c => c.GetParameters().Length).FirstOrDefault()));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Configures the part as instance per Http request
 /// </summary>
 /// <param name="partConventionBuilder"></param>
 /// <returns></returns>
 public static PartConventionBuilder InstancePerHttpRequest(this PartConventionBuilder partConventionBuilder)
 {
     return(partConventionBuilder.Shared(Constants.InstancePerRequestBoundaryName));
 }