/// <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); }
/// <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); }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
public static PartConventionBuilder ExportInterfaces(this PartConventionBuilder pb) { return(null); }
/// <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())); }
/// <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)); }