@@ -192,116 +192,91 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
192
192
return GetXResult . Ambiguous ;
193
193
}
194
194
}
195
-
196
- if ( member != null )
197
- {
198
- return GetXResult . Single ;
199
- }
200
-
201
- if ( targetType . TryFindFirstMemberRecursive ( name , out member ) )
202
- {
203
- if ( IsUseContainingType ( member ) )
204
- {
205
- return GetXResult . UseContainingType ;
206
- }
207
-
208
- if ( member . MetadataName == targetMetadataName &&
209
- ! MatchesFilter ( member , member . MetadataName , flags , null ) )
210
- {
211
- return GetXResult . WrongFlags ;
212
- }
213
-
214
- if ( ! member . ContainingType . Equals ( targetType ) &&
215
- ( member . IsStatic ||
216
- flags . HasFlagFast ( BindingFlags . DeclaredOnly ) ) )
217
- {
218
- return GetXResult . WrongFlags ;
219
- }
220
- }
221
-
222
- if ( IsExplicitImplementation ( out member ) )
223
- {
224
- return GetXResult . ExplicitImplementation ;
225
- }
226
-
227
- if ( flags . HasFlagFast ( BindingFlags . NonPublic ) &&
228
- ! targetType . Locations . Any ( x => x . IsInSource ) )
229
- {
230
- return GetXResult . Unknown ;
231
- }
232
-
233
- return GetXResult . NoMatch ;
234
195
}
235
-
236
- var current = targetType ;
237
- while ( current != null )
196
+ else
238
197
{
239
- foreach ( var candidate in current . GetMembers ( name ) )
198
+ var current = targetType ;
199
+ while ( current != null )
240
200
{
241
- if ( ! MatchesFilter ( candidate , targetMetadataName , flags , types ) )
242
- {
243
- continue ;
244
- }
245
-
246
- if ( IsOverriding ( member , candidate ) )
247
- {
248
- continue ;
249
- }
250
-
251
- if ( member == null )
201
+ foreach ( var candidate in current . GetMembers ( name ) )
252
202
{
253
- member = candidate ;
254
- if ( IsUseContainingType ( member ) )
203
+ if ( ! MatchesFilter ( candidate , targetMetadataName , flags , types ) )
255
204
{
256
- return GetXResult . UseContainingType ;
205
+ continue ;
257
206
}
258
207
259
- if ( candidate . IsStatic &&
260
- ! current . Equals ( targetType ) &&
261
- ! flags . HasFlagFast ( BindingFlags . FlattenHierarchy ) )
208
+ if ( IsOverriding ( member , candidate ) )
262
209
{
263
- return GetXResult . WrongFlags ;
210
+ continue ;
264
211
}
265
212
266
- if ( IsWrongMemberType ( candidate ) )
213
+ if ( member == null )
267
214
{
268
- return GetXResult . WrongMemberType ;
215
+ member = candidate ;
216
+ if ( IsUseContainingType ( member ) )
217
+ {
218
+ return GetXResult . UseContainingType ;
219
+ }
220
+
221
+ if ( candidate . IsStatic &&
222
+ ! current . Equals ( targetType ) &&
223
+ ! flags . HasFlagFast ( BindingFlags . FlattenHierarchy ) )
224
+ {
225
+ return GetXResult . WrongFlags ;
226
+ }
227
+
228
+ if ( IsWrongMemberType ( candidate ) )
229
+ {
230
+ return GetXResult . WrongMemberType ;
231
+ }
232
+ }
233
+ else
234
+ {
235
+ return GetXResult . Ambiguous ;
269
236
}
270
237
}
271
- else
272
- {
273
- return GetXResult . Ambiguous ;
274
- }
238
+
239
+ current = current . BaseType ;
275
240
}
241
+ }
276
242
277
- current = current . BaseType ;
243
+ if ( member != null )
244
+ {
245
+ return GetXResult . Single ;
278
246
}
279
247
280
- if ( member == null )
248
+ if ( targetType . TryFindFirstMemberRecursive ( name , out member ) )
281
249
{
282
- if ( targetType . TryFindFirstMemberRecursive ( name , out member ) )
250
+ if ( IsUseContainingType ( member ) )
283
251
{
284
- if ( member . MetadataName == targetMetadataName &&
285
- ! MatchesFilter ( member , member . MetadataName , flags , null ) )
286
- {
287
- return GetXResult . WrongFlags ;
288
- }
252
+ return GetXResult . UseContainingType ;
289
253
}
290
254
291
- if ( IsExplicitImplementation ( out member ) )
255
+ if ( member . MetadataName == targetMetadataName &&
256
+ ! MatchesFilter ( member , member . MetadataName , flags , null ) )
292
257
{
293
- return GetXResult . ExplicitImplementation ;
258
+ return GetXResult . WrongFlags ;
294
259
}
295
260
296
- if ( ! HasVisibleMembers ( targetType , flags ) )
261
+ if ( ! member . ContainingType . Equals ( targetType ) &&
262
+ ( member . IsStatic ||
263
+ flags . HasFlagFast ( BindingFlags . DeclaredOnly ) ) )
297
264
{
298
- return GetXResult . Unknown ;
265
+ return GetXResult . WrongFlags ;
299
266
}
267
+ }
300
268
301
- return GetXResult . NoMatch ;
269
+ if ( IsExplicitImplementation ( out member ) )
270
+ {
271
+ return GetXResult . ExplicitImplementation ;
302
272
}
303
273
304
- return GetXResult . Single ;
274
+ if ( ! HasVisibleMembers ( targetType , flags ) )
275
+ {
276
+ return GetXResult . Unknown ;
277
+ }
278
+
279
+ return GetXResult . NoMatch ;
305
280
306
281
bool IsWrongMemberType ( ISymbol symbol )
307
282
{
@@ -626,29 +601,29 @@ private static bool MatchesFilter(ISymbol candidate, string metadataName, Bindin
626
601
627
602
private static bool HasVisibleMembers ( ITypeSymbol type , BindingFlags effectiveFlags )
628
603
{
629
- if ( effectiveFlags . HasFlagFast ( BindingFlags . NonPublic ) )
604
+ if ( ! effectiveFlags . HasFlagFast ( BindingFlags . NonPublic ) )
630
605
{
631
- return ! HasSuperTypeNotInSource ( ) ;
606
+ return true ;
632
607
}
633
608
634
- return true ;
609
+ if ( effectiveFlags . HasFlagFast ( BindingFlags . DeclaredOnly ) )
610
+ {
611
+ return type . Locations . Any ( x => x . IsInSource ) ;
612
+ }
635
613
636
- bool HasSuperTypeNotInSource ( )
614
+ var current = type ;
615
+ while ( current != null &&
616
+ current != KnownSymbol . Object )
637
617
{
638
- var current = type ;
639
- while ( current != null &&
640
- current != KnownSymbol . Object )
618
+ if ( ! current . Locations . Any ( x => x . IsInSource ) )
641
619
{
642
- if ( ! current . Locations . Any ( x => x . IsInSource ) )
643
- {
644
- return true ;
645
- }
646
-
647
- current = current . BaseType ;
620
+ return false ;
648
621
}
649
622
650
- return false ;
623
+ current = current . BaseType ;
651
624
}
625
+
626
+ return true ;
652
627
}
653
628
654
629
private static bool TryGetTargetType ( ExpressionSyntax expression , SyntaxNodeAnalysisContext context , PooledSet < ExpressionSyntax > visited , out ITypeSymbol result , out Optional < IdentifierNameSyntax > instance )
0 commit comments