in extensions/Worker.Extensions.Storage.Blobs/src/BlobStorageConverter.cs [101:144]
private async Task<object?> ConvertModelBindingDataAsync(Type targetType, BlobBindingData blobData)
{
if (blobData is null)
{
throw new ArgumentNullException(nameof(blobData));
}
if (string.IsNullOrEmpty(blobData.Connection))
{
throw new InvalidOperationException($"'{nameof(blobData.Connection)}' cannot be null or empty.");
}
if (string.IsNullOrEmpty(blobData.ContainerName))
{
throw new InvalidOperationException($"'{nameof(blobData.ContainerName)}' cannot be null or empty.");
}
BlobContainerClient container = CreateBlobContainerClient(blobData.Connection!, blobData.ContainerName!);
if (IsCollectionBinding(targetType, blobData.BlobName!, out Type? elementType))
{
if (elementType is null)
{
throw new InvalidOperationException($"Unable to determine element type for collection binding to type '{targetType.Name}'.");
}
return await BindToCollectionAsync(targetType, elementType, container, blobData.BlobName!);
}
else
{
if (targetType == typeof(BlobContainerClient) && BlobIsFileRegex.IsMatch(blobData.BlobName))
{
throw new InvalidOperationException("Binding to a BlobContainerClient with a blob path is not supported. "
+ "Either bind to the container path, or use BlobClient instead.");
}
if (targetType != typeof(BlobContainerClient) && string.IsNullOrEmpty(blobData.BlobName))
{
throw new InvalidOperationException($"'{nameof(blobData.BlobName)}' cannot be null or empty when binding to a single blob.");
}
return await ToTargetTypeAsync(targetType, container, blobData.BlobName!);
}
}