in src/Microsoft.Azure.WebJobs.Host/Bindings/BindingProviders/GenericCompositeBindingProvider.cs [41:90]
public async Task<IBinding> TryCreateAsync(BindingProviderContext context)
{
var attr = context.Parameter.GetCustomAttribute<TAttribute>();
if (attr == null)
{
return null;
}
if (_validator != null)
{
// Expected this will throw on errors.
Type parameterType = context.Parameter.ParameterType;
var cloner = new AttributeCloner<TAttribute>(attr, context.BindingDataContract, _configuration, _nameResolver);
var attrNameResolved = cloner.GetNameResolvedAttribute();
_validator(attrNameResolved, parameterType);
}
foreach (IBindingProvider provider in _providers)
{
IBinding binding = await provider.TryCreateAsync(context);
if (binding != null)
{
return binding;
}
}
// Nobody claimed it.
string resourceName = typeof(TAttribute).Name;
const string Suffix = "Attribute";
if (resourceName.EndsWith(Suffix))
{
resourceName = resourceName.Substring(0, resourceName.Length - Suffix.Length);
}
StringBuilder exceptionMessage = new StringBuilder($"Can't bind {resourceName} to type '{context.Parameter.ParameterType}'.");
if (context.BindingErrors.Count > 0)
{
exceptionMessage.AppendLine().AppendLine("Possible causes:");
var index = 0;
foreach (var error in context.BindingErrors)
{
exceptionMessage.AppendLine($"{++index}) {error}");
}
}
throw new InvalidOperationException(exceptionMessage.ToString());
}