@@ -75,14 +75,13 @@ private static IReadOnlyList<Attribute> GetAttributes(MemberInfo member, Type at
7575 t => ExtractAttributes ( t , out var count ) . ToArray ( count )
7676 ) ;
7777
78- private static Attribute [ ] GetAttributes ( this MemberInfo member , Type attributeType )
78+ private static IEnumerable < Attribute > GetAttributes ( this MemberInfo member , Type attributeType , out int count )
7979 {
8080 var attrObjects = member . GetCustomAttributes ( attributeType , false ) ;
81- var attrs = new Attribute [ attrObjects . Length ] ;
82- for ( int i = attrObjects . Length ; i -- > 0 ; ) {
83- attrs [ i ] = ( Attribute ) attrObjects [ i ] ;
84- }
85- return attrs ;
81+ count = attrObjects . Length ;
82+ return ( count == 0 )
83+ ? Array . Empty < Attribute > ( )
84+ : attrObjects . Cast < Attribute > ( ) ;
8685 }
8786
8887 private static IEnumerable < Attribute > ExtractAttributes ( ( MemberInfo member , Type attributeType , AttributeSearchOptions options ) t , out int count )
@@ -95,7 +94,7 @@ private static IEnumerable<Attribute> ExtractAttributes((MemberInfo member, Type
9594 if ( options == AttributeSearchOptions . InheritNone ) {
9695 return ( customAttributesRaw . Length == 0 )
9796 ? Array . Empty < Attribute > ( )
98- : customAttributesRaw . Cast < Attribute > ( ) ; // no new collection
97+ : customAttributesRaw . Cast < Attribute > ( ) ;
9998 }
10099
101100 IEnumerable < Attribute > attributes ;
@@ -104,8 +103,8 @@ private static IEnumerable<Attribute> ExtractAttributes((MemberInfo member, Type
104103 if ( ( options & AttributeSearchOptions . InheritFromPropertyOrEvent ) != 0
105104 && member is MethodInfo m
106105 && ( ( MemberInfo ) m . GetProperty ( ) ?? m . GetEvent ( ) ) is MemberInfo poe ) {
107- var poeAttributes = poe . GetAttributes ( attributeType ) ;
108- count = poeAttributes . Length ;
106+ var poeAttributes = poe . GetAttributes ( attributeType , out var count1 ) ;
107+ count = count1 ;
109108 attributes = poeAttributes ;
110109 }
111110 if ( ( options & AttributeSearchOptions . InheritFromBase ) != 0
0 commit comments