@@ -83,58 +83,67 @@ protected IEnumerable<Type> FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumera
83
83
/// Gets the assembly types annotated with <see cref="DynamicLinqTypeAttribute"/> in an Exception friendly way.
84
84
/// </summary>
85
85
/// <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 )
88
88
{
89
89
Check . NotNull ( assemblies ) ;
90
90
91
+ var dynamicLinqTypes = new List < Type > ( ) ;
92
+
91
93
foreach ( var assembly in assemblies )
92
94
{
93
- var definedTypes = Type . EmptyTypes ;
95
+ Type [ ] definedTypes ;
94
96
95
97
try
96
98
{
97
- definedTypes = assembly . ExportedTypes . ToArray ( ) ;
98
- }
99
- catch ( ReflectionTypeLoadException reflectionTypeLoadException )
100
- {
101
- definedTypes = reflectionTypeLoadException . Types . WhereNotNull ( ) . ToArray ( ) ;
99
+ definedTypes = assembly . GetExportedTypes ( ) ;
102
100
}
103
101
catch
104
102
{
105
103
// Ignore all other exceptions
104
+ definedTypes = Type . EmptyTypes ;
106
105
}
107
106
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 )
113
108
{
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
+ }
115
120
}
116
121
}
122
+
123
+ return dynamicLinqTypes . Distinct ( ) . ToArray ( ) ;
117
124
}
118
125
#else
119
126
/// <summary>
120
127
/// Gets the assembly types annotated with <see cref="DynamicLinqTypeAttribute"/> in an Exception friendly way.
121
128
/// </summary>
122
129
/// <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 )
125
132
{
126
133
Check . NotNull ( assemblies ) ;
127
134
135
+ var dynamicLinqTypes = new List < Type > ( ) ;
136
+
128
137
#if ! NET5_0_OR_GREATER
129
138
assemblies = assemblies . Where ( a => ! a . GlobalAssemblyCache ) . ToArray ( ) ; // Skip System DLL's
130
139
#endif
131
140
foreach ( var assembly in assemblies )
132
141
{
133
- var definedTypes = Type . EmptyTypes ;
142
+ Type [ ] definedTypes ;
134
143
135
144
try
136
145
{
137
- definedTypes = assembly . GetExportedTypes ( ) . ToArray ( ) ;
146
+ definedTypes = assembly . GetTypes ( ) ;
138
147
}
139
148
catch ( ReflectionTypeLoadException reflectionTypeLoadException )
140
149
{
@@ -143,29 +152,26 @@ protected IEnumerable<Type> GetAssemblyTypesWithDynamicLinqTypeAttribute(IEnumer
143
152
catch
144
153
{
145
154
// Ignore all other exceptions
155
+ definedTypes = Type . EmptyTypes ;
146
156
}
147
157
148
- var filtered = new List < Type > ( ) ;
149
158
foreach ( var definedType in definedTypes )
150
159
{
151
160
try
152
161
{
153
162
if ( definedType . IsDefined ( typeof ( DynamicLinqTypeAttribute ) , false ) )
154
163
{
155
- filtered . Add ( definedType ) ;
164
+ dynamicLinqTypes . Add ( definedType ) ;
156
165
}
157
166
}
158
167
catch
159
168
{
160
169
// Ignore
161
170
}
162
171
}
163
-
164
- foreach ( var definedType in filtered . Distinct ( ) . ToArray ( ) )
165
- {
166
- yield return definedType ;
167
- }
168
172
}
173
+
174
+ return dynamicLinqTypes . Distinct ( ) . ToArray ( ) ;
169
175
}
170
176
#endif
171
177
}
0 commit comments