问题
Is there a way to get the property of Azure blob dynamically without explicitly mentioning it.
Example, if I want to get the created date of blob then I need to write something like this
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("Storage Account")
CloudBlobClient sourceBlobClient = storageAccount.CreateCloudBlobClient();
var sourceContainer = sourceBlobClient.GetContainerReference("Container Name");
var blockBlob = blobContainer.GetBlockBlobReference("Blob Name");
blockBlob.FetchAttributesAsync().Wait();
var blobCreatedDate = blockBlob.Properties.Created;
I am trying to avoid explicitly mentioning "Created" present in the last statement.
Any pointer to get this achieved ? can we loop through the properties of blob ?
回答1:
Finally I was able to achieve it like this
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("Storage Account")
CloudBlobClient sourceBlobClient = storageAccount.CreateCloudBlobClient();
var sourceContainer = sourceBlobClient.GetContainerReference("Container Name");
var blockBlob = blobContainer.GetBlockBlobReference("Blob Name");
blockBlob.FetchAttributesAsync().Wait();
//var blobCreatedDate = blockBlob.Properties.Created;
var propName = "Created"
Type tModelType = blockBlob.Properties.GetType();
var propertyInfo = tModelType.GetProperty(propName);
If (propertyInfo != null) {
var blobCreatedDate = propertyInfo.GetValue(blockBlob.Properties).ToString();
}
来源:https://stackoverflow.com/questions/53815887/dynamically-get-the-value-of-azure-blob-property