2011-09-01 16 views
0

属性のすべてのリストを反復せずにカスタム属性値を読み取ることは可能ですか?私は属性値attributeData.IncludeResultを読むために以下のコードを使用しますが、私はforeachと繰り返しを使用せずに簡単にもっと最適な方法で行うべきだと思います。反復なしで属性を取得

foreach (var customAttributeData in 
     propertyInfo.GetCustomAttributes(typeof(WebClientAttribute), false)) 
{ 
    var attributeData = (WebClientAttribute)customAttributeData; 
    myData = attributeData.IncludeResult 
} 

答えて

2

あなたが欲しい:

WebClientAttribute attrib = (WebClientAttribute) 
    Attribute.GetCustomAttribute(propertyInfo, typeof(WebClientAttribute)); 
関連する問題