/// <summary> /// Bind a parameter to an IAsyncCollector. Use this for things that have discrete output items (like sending messages or writing table rows) /// This will add additional adapters to connect the user's parameter type to an IAsyncCollector. /// </summary> /// <typeparam name="TMessage">The 'core type' for the IAsyncCollector.</typeparam> /// <typeparam name="TTriggerValue">The type of the trigger object to pass to the listener.</typeparam> /// <param name="bindingStrategy">A strategy object that describes how to do the binding</param> /// <param name="parameter">The user's parameter being bound to</param> /// <param name="converterManager">The converter manager, used to convert between the user parameter's type and the underlying native types used by the trigger strategy</param> /// <param name="createListener">A function to create the underlying listener for this parameter</param> /// <returns>A trigger binding</returns> public static ITriggerBinding GetTriggerBinding <TMessage, TTriggerValue>( ITriggerBindingStrategy <TMessage, TTriggerValue> bindingStrategy, ParameterInfo parameter, IConverterManager converterManager, Func <ListenerFactoryContext, bool, Task <IListener> > createListener) { if (bindingStrategy == null) { throw new ArgumentNullException("bindingStrategy"); } if (parameter == null) { throw new ArgumentNullException("parameter"); } bool singleDispatch; var argumentBinding = BindingFactoryHelpers.GetTriggerArgumentBinding(bindingStrategy, parameter, converterManager, out singleDispatch); var parameterDescriptor = new ParameterDescriptor { Name = parameter.Name, DisplayHints = new ParameterDisplayHints { Description = singleDispatch ? "message" : "messages" } }; ITriggerBinding binding = new StrategyTriggerBinding <TMessage, TTriggerValue>( bindingStrategy, argumentBinding, createListener, parameterDescriptor, singleDispatch); return(binding); }
// Called once per method definition. Very static. public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; TAttribute attribute = parameter.GetCustomAttribute <TAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } IBinding binding = BindingFactoryHelpers.BindCollector <TAttribute, TMessage>( parameter, _nameResolver, _converterManager, context.BindingDataContract, _buildFromAttribute, _buildParamDescriptor, _postResolveHook); return(Task.FromResult(binding)); }
public override IBinding CreateBinding() { IBinding binding = BindingFactoryHelpers.BindCollector <TAttribute, TMessage>( Parameter, NameResolver, new IdentityConverterManager(), this.Context.BindingDataContract, this.BuildFromAttribute, null); return(binding); }
// Called once per method definition. Very static. public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; TAttribute attribute = parameter.GetCustomAttribute <TAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } // Now we can instantiate against the user's type. // throws if can't infer the type. Type typeMessage = BindingFactoryHelpers.GetAsyncCollectorCoreType(parameter.ParameterType); if (typeMessage == null) { // incompatible type. Skip. return(Task.FromResult <IBinding>(null)); } // Apply filter var cloner = new AttributeCloner <TAttribute>(attribute, context.BindingDataContract, _nameResolver); var attrNameResolved = cloner.GetNameResolvedAttribute(); bool canUse = _filter(attrNameResolved, typeMessage); if (!canUse) { return(Task.FromResult <IBinding>(null)); } var wrapper = WrapperBase.New( typeMessage, _builder, _nameResolver, parameter, context); IBinding binding = wrapper.CreateBinding(); return(Task.FromResult(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } var parameter = context.Parameter; var typeUser = parameter.ParameterType; if (typeUser.IsByRef) { return(Task.FromResult <IBinding>(null)); } var type = typeof(ExactBinding <>).MakeGenericType(typeof(TAttribute), typeof(TType), typeUser); var method = type.GetMethod("TryBuild", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); var binding = BindingFactoryHelpers.MethodInvoke <IBinding>(method, this, context); return(Task.FromResult <IBinding>(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } var parameter = context.Parameter; var typeUser = parameter.ParameterType; if (typeUser.IsByRef) { typeUser = typeUser.GetElementType(); // Can't generic instantiate a ByRef. } var type = typeof(StreamBinding); var method = type.GetMethod("TryBuild", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); method = method.MakeGenericMethod(typeUser); var binding = BindingFactoryHelpers.MethodInvoke <IBinding>(method, this, context); return(Task.FromResult <IBinding>(binding)); }