Dynamically get the value of Azure blob property

穿精又带淫゛_ 提交于 2019-12-12 01:19:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!