@@ -83,58 +83,67 @@ protected IEnumerable<Type> FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumera
8383 /// Gets the assembly types annotated with <see cref="DynamicLinqTypeAttribute"/> in an Exception friendly way.
8484 /// </summary>
8585 /// <param name="assemblies">The assemblies to process.</param>
86- /// <returns><see cref="IEnumerable{ Type} " /></returns>
87- protected IEnumerable < Type > GetAssemblyTypesWithDynamicLinqTypeAttribute ( IEnumerable < Assembly > assemblies )
86+ /// <returns>Array of <see cref="Type" /></returns>
87+ protected Type [ ] GetAssemblyTypesWithDynamicLinqTypeAttribute ( IEnumerable < Assembly > assemblies )
8888 {
8989 Check . NotNull ( assemblies ) ;
9090
91+ var dynamicLinqTypes = new List < Type > ( ) ;
92+
9193 foreach ( var assembly in assemblies )
9294 {
93- var definedTypes = Type . EmptyTypes ;
95+ Type [ ] definedTypes ;
9496
9597 try
9698 {
97- definedTypes = assembly . ExportedTypes . ToArray ( ) ;
98- }
99- catch ( ReflectionTypeLoadException reflectionTypeLoadException )
100- {
101- definedTypes = reflectionTypeLoadException . Types . WhereNotNull ( ) . ToArray ( ) ;
99+ definedTypes = assembly . GetExportedTypes ( ) ;
102100 }
103101 catch
104102 {
105103 // Ignore all other exceptions
104+ definedTypes = Type . EmptyTypes ;
106105 }
107106
108- var filteredAndDistinct = definedTypes
109- . Where ( t => t . GetTypeInfo ( ) . IsDefined ( typeof ( DynamicLinqTypeAttribute ) , false ) )
110- . Distinct ( ) ;
111-
112- foreach ( var definedType in filteredAndDistinct )
107+ foreach ( var definedType in definedTypes )
113108 {
114- yield return definedType ;
109+ try
110+ {
111+ if ( definedType . GetTypeInfo ( ) . IsDefined ( typeof ( DynamicLinqTypeAttribute ) , false ) )
112+ {
113+ dynamicLinqTypes . Add ( definedType ) ;
114+ }
115+ }
116+ catch
117+ {
118+ // Ignore
119+ }
115120 }
116121 }
122+
123+ return dynamicLinqTypes . Distinct ( ) . ToArray ( ) ;
117124 }
118125#else
119126 /// <summary>
120127 /// Gets the assembly types annotated with <see cref="DynamicLinqTypeAttribute"/> in an Exception friendly way.
121128 /// </summary>
122129 /// <param name="assemblies">The assemblies to process.</param>
123- /// <returns><see cref="IEnumerable{ Type} " /></returns>
124- protected IEnumerable < Type > GetAssemblyTypesWithDynamicLinqTypeAttribute ( IEnumerable < Assembly > assemblies )
130+ /// <returns>Array of <see cref="Type" /></returns>
131+ protected Type [ ] GetAssemblyTypesWithDynamicLinqTypeAttribute ( IEnumerable < Assembly > assemblies )
125132 {
126133 Check . NotNull ( assemblies ) ;
127134
135+ var dynamicLinqTypes = new List < Type > ( ) ;
136+
128137#if ! NET5_0_OR_GREATER
129138 assemblies = assemblies . Where ( a => ! a . GlobalAssemblyCache ) . ToArray ( ) ; // Skip System DLL's
130139#endif
131140 foreach ( var assembly in assemblies )
132141 {
133- var definedTypes = Type . EmptyTypes ;
142+ Type [ ] definedTypes ;
134143
135144 try
136145 {
137- definedTypes = assembly . GetExportedTypes ( ) . ToArray ( ) ;
146+ definedTypes = assembly . GetTypes ( ) ;
138147 }
139148 catch ( ReflectionTypeLoadException reflectionTypeLoadException )
140149 {
@@ -143,29 +152,26 @@ protected IEnumerable<Type> GetAssemblyTypesWithDynamicLinqTypeAttribute(IEnumer
143152 catch
144153 {
145154 // Ignore all other exceptions
155+ definedTypes = Type . EmptyTypes ;
146156 }
147157
148- var filtered = new List < Type > ( ) ;
149158 foreach ( var definedType in definedTypes )
150159 {
151160 try
152161 {
153162 if ( definedType . IsDefined ( typeof ( DynamicLinqTypeAttribute ) , false ) )
154163 {
155- filtered . Add ( definedType ) ;
164+ dynamicLinqTypes . Add ( definedType ) ;
156165 }
157166 }
158167 catch
159168 {
160169 // Ignore
161170 }
162171 }
163-
164- foreach ( var definedType in filtered . Distinct ( ) . ToArray ( ) )
165- {
166- yield return definedType ;
167- }
168172 }
173+
174+ return dynamicLinqTypes . Distinct ( ) . ToArray ( ) ;
169175 }
170176#endif
171177}
0 commit comments