Beispiel #1
0
        /// <summary>
        /// Bind an attribute to the given input, using the supplied delegate to build the input from an resolved
        /// instance of the attribute.
        /// </summary>
        /// <typeparam name="TType"></typeparam>
        /// <param name="builder"></param>
        /// <returns></returns>
        public void BindToInput <TType>(Func <TAttribute, TType> builder)
        {
            var builderInstance = new DelegateConverterBuilder <TAttribute, TType> {
                BuildFromAttribute = builder
            };

            this.BindToInput <TType>(builderInstance);
        }
Beispiel #2
0
        /// <summary>
        /// Bind to a collector
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="buildFromAttribute"></param>
        /// <returns></returns>
        public void BindToCollector <TMessage>(
            Func <TAttribute, IAsyncCollector <TMessage> > buildFromAttribute)
        {
            var converter = new DelegateConverterBuilder <TAttribute, IAsyncCollector <TMessage> > {
                BuildFromAttribute = buildFromAttribute
            };

            BindToCollector(converter);
        }
        /// <summary>
        /// Create a binding provider for binding a parameter to an <see cref="IAsyncCollector{TMEssage}"/>.
        /// Use the <see cref="IConverterManager"/> to convert form the user's parameter type to the TMessage type.
        /// </summary>
        /// <typeparam name="TAttribute">Type of binding attribute on the user's parameter.</typeparam>
        /// <typeparam name="TMessage">element type of the IAsyncCollector.</typeparam>
        /// <param name="buildFromAttribute">Function to allocate the collector object given a resolved instance of the attribute.</param>
        /// <returns>A binding provider that applies these semantics.</returns>
        public IBindingProvider BindToCollector <TAttribute, TMessage>(
            Func <TAttribute, IAsyncCollector <TMessage> > buildFromAttribute)
            where TAttribute : Attribute
        {
            var converter = new DelegateConverterBuilder <TAttribute, IAsyncCollector <TMessage> > {
                BuildFromAttribute = buildFromAttribute
            };
            var pm = PatternMatcher.New(converter);

            return(new AsyncCollectorBindingProvider <TAttribute, TMessage>(this._nameResolver, this._converterManager, pm));
        }