开发者

Get attribute without iteration

开发者 https://www.devze.com 2023-04-01 23:31 出处:网络
Is it possible to read custom attribute value without iterating through all list of attributes? I use code below to read attribute value attributeData.IncludeResult but I think should easy more optima

Is it possible to read custom attribute value without iterating through all list of attributes? I use code below to read attribute value attributeData.IncludeResult but I think should easy more optimal way to do that without using foreach and iteration.

foreach (var customAttributeData in
         propertyInfo.GetCustomAttributes(typeof(WebClientAttribute), false))
{
    var attributeData = (WebClientAttribute)customAttributeData;
    myData = attributeData.Inc开发者_运维技巧ludeResult
}


You want:

WebClientAttribute attrib = (WebClientAttribute)
    Attribute.GetCustomAttribute(propertyInfo, typeof(WebClientAttribute));
0

精彩评论

暂无评论...
验证码 换一张
取 消