是否有一种方法可以动态获取Azure blob的属性而无需明确提及。
例如,如果我想获取blob的创建日期,则需要编写如下内容
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”。
有没有实现这一目标的指针?我们可以遍历Blob的属性吗?
答案 0 :(得分:0)
最后,我能够做到这一点
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();
}