public Task TryCreateAsync()

in src/TriggerBinding/SqlTriggerBindingProvider.cs [53:100]


        public Task<ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ParameterInfo parameter = context.Parameter;
            SqlTriggerAttribute attribute = parameter.GetCustomAttribute<SqlTriggerAttribute>(inherit: false);

            // During application startup, the WebJobs SDK calls 'TryCreateAsync' method of all registered trigger
            // binding providers in sequence for each parameter in the user function. A provider that finds the
            // parameter-attribute that it can handle returns the binding object. Rest of the providers are supposed to
            // return null. This binding object later gets used for binding before every function invocation.
            if (attribute == null)
            {
                return Task.FromResult<ITriggerBinding>(null);
            }

            Type parameterType = parameter.ParameterType;
            if (!IsValidTriggerParameterType(parameterType))
            {
                throw new InvalidOperationException($"Can't bind SqlTriggerAttribute to type {parameter.ParameterType}, this is not a supported type.");
            }

            string connectionString = SqlBindingUtilities.GetConnectionString(attribute.ConnectionStringSetting, this._configuration);

            Type bindingType;
            // Instantiate class 'SqlTriggerBinding<JObject>' for non .NET In-Proc functions.
            if (parameterType == typeof(string))
            {
                bindingType = typeof(SqlTriggerBinding<>).MakeGenericType(typeof(JObject));
            }
            else
            {
                // Extract the POCO type 'T' and use it to instantiate class 'SqlTriggerBinding<T>'.
                Type userType = parameter.ParameterType.GetGenericArguments()[0].GetGenericArguments()[0];
                bindingType = typeof(SqlTriggerBinding<>).MakeGenericType(userType);
            }

            var constructorParameterTypes = new Type[] { typeof(string), typeof(string), typeof(string), typeof(ParameterInfo), typeof(IOptions<SqlOptions>), typeof(IHostIdProvider), typeof(ILogger), typeof(IConfiguration) };
            ConstructorInfo bindingConstructor = bindingType.GetConstructor(constructorParameterTypes);

            object[] constructorParameterValues = new object[] { connectionString, attribute.TableName, attribute.LeasesTableName, parameter, this._sqlOptions, this._hostIdProvider, this._logger, this._configuration };
            var triggerBinding = (ITriggerBinding)bindingConstructor.Invoke(constructorParameterValues);

            return Task.FromResult(triggerBinding);
        }