in src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBTriggerAttributeBindingProviderGenerator.cs [40:79]
public Task<ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
{
CosmosDBTriggerAttribute cosmosDBTriggerAttribute = context.Parameter.GetCustomAttribute<CosmosDBTriggerAttribute>(inherit: false);
if (cosmosDBTriggerAttribute == null)
{
return Task.FromResult<ITriggerBinding>(null);
}
Type documentType = CosmosDBTriggerAttributeBindingProviderGenerator.GetParameterType(context.Parameter);
if (typeof(JArray).IsAssignableFrom(documentType)
|| typeof(JObject[]).IsAssignableFrom(documentType))
{
documentType = typeof(JObject); // When binding to JArray, use JObject as contract.
}
if (typeof(string).IsAssignableFrom(documentType))
{
documentType = typeof(JObject);
}
Type baseType = typeof(CosmosDBTriggerAttributeBindingProvider<>);
Type genericBindingType = baseType.MakeGenericType(documentType);
Type[] typeArgs = { typeof(INameResolver), typeof(CosmosDBOptions), typeof(CosmosDBExtensionConfigProvider), typeof(IDrainModeManager), typeof(ILoggerFactory) };
ConstructorInfo constructor = genericBindingType.GetConstructor(typeArgs);
object[] constructorParameterValues = { _nameResolver, _options, _configProvider, _drainModeManager, _loggerFactory };
object cosmosDBTriggerAttributeBindingProvider = constructor.Invoke(constructorParameterValues);
MethodInfo methodInfo = genericBindingType.GetMethod(nameof(CosmosDBTriggerAttributeBindingProvider<dynamic>.TryCreateAsync));
object[] methodParameterValues = { context };
return (Task<ITriggerBinding>)methodInfo.Invoke(cosmosDBTriggerAttributeBindingProvider, methodParameterValues);
}