动态获取Azure blob属性的值 [英] Dynamically get the value of Azure blob property
本文介绍了动态获取Azure blob属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以动态获取Azure blob的属性而无需明确提及.
Is there a way to get the property of Azure blob dynamically without explicitly mentioning it.
例如,如果我想获取blob的创建日期,则需要编写如下内容
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;
我试图避免在最后一个语句中明确提及存在的"Created".
I am trying to avoid explicitly mentioning "Created" present in the last statement.
有没有实现这一目标的指针?我们可以遍历blob的属性吗?
Any pointer to get this achieved ? can we loop through the properties of blob ?
推荐答案
最后,我能够做到这一点
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();
}
这篇关于动态获取Azure blob属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文