@@ -192,116 +192,91 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
192192 return GetXResult . Ambiguous ;
193193 }
194194 }
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 ;
234195 }
235-
236- var current = targetType ;
237- while ( current != null )
196+ else
238197 {
239- foreach ( var candidate in current . GetMembers ( name ) )
198+ var current = targetType ;
199+ while ( current != null )
240200 {
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 ) )
252202 {
253- member = candidate ;
254- if ( IsUseContainingType ( member ) )
203+ if ( ! MatchesFilter ( candidate , targetMetadataName , flags , types ) )
255204 {
256- return GetXResult . UseContainingType ;
205+ continue ;
257206 }
258207
259- if ( candidate . IsStatic &&
260- ! current . Equals ( targetType ) &&
261- ! flags . HasFlagFast ( BindingFlags . FlattenHierarchy ) )
208+ if ( IsOverriding ( member , candidate ) )
262209 {
263- return GetXResult . WrongFlags ;
210+ continue ;
264211 }
265212
266- if ( IsWrongMemberType ( candidate ) )
213+ if ( member == null )
267214 {
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 ;
269236 }
270237 }
271- else
272- {
273- return GetXResult . Ambiguous ;
274- }
238+
239+ current = current . BaseType ;
275240 }
241+ }
276242
277- current = current . BaseType ;
243+ if ( member != null )
244+ {
245+ return GetXResult . Single ;
278246 }
279247
280- if ( member == null )
248+ if ( targetType . TryFindFirstMemberRecursive ( name , out member ) )
281249 {
282- if ( targetType . TryFindFirstMemberRecursive ( name , out member ) )
250+ if ( IsUseContainingType ( member ) )
283251 {
284- if ( member . MetadataName == targetMetadataName &&
285- ! MatchesFilter ( member , member . MetadataName , flags , null ) )
286- {
287- return GetXResult . WrongFlags ;
288- }
252+ return GetXResult . UseContainingType ;
289253 }
290254
291- if ( IsExplicitImplementation ( out member ) )
255+ if ( member . MetadataName == targetMetadataName &&
256+ ! MatchesFilter ( member , member . MetadataName , flags , null ) )
292257 {
293- return GetXResult . ExplicitImplementation ;
258+ return GetXResult . WrongFlags ;
294259 }
295260
296- if ( ! HasVisibleMembers ( targetType , flags ) )
261+ if ( ! member . ContainingType . Equals ( targetType ) &&
262+ ( member . IsStatic ||
263+ flags . HasFlagFast ( BindingFlags . DeclaredOnly ) ) )
297264 {
298- return GetXResult . Unknown ;
265+ return GetXResult . WrongFlags ;
299266 }
267+ }
300268
301- return GetXResult . NoMatch ;
269+ if ( IsExplicitImplementation ( out member ) )
270+ {
271+ return GetXResult . ExplicitImplementation ;
302272 }
303273
304- return GetXResult . Single ;
274+ if ( ! HasVisibleMembers ( targetType , flags ) )
275+ {
276+ return GetXResult . Unknown ;
277+ }
278+
279+ return GetXResult . NoMatch ;
305280
306281 bool IsWrongMemberType ( ISymbol symbol )
307282 {
@@ -626,29 +601,29 @@ private static bool MatchesFilter(ISymbol candidate, string metadataName, Bindin
626601
627602 private static bool HasVisibleMembers ( ITypeSymbol type , BindingFlags effectiveFlags )
628603 {
629- if ( effectiveFlags . HasFlagFast ( BindingFlags . NonPublic ) )
604+ if ( ! effectiveFlags . HasFlagFast ( BindingFlags . NonPublic ) )
630605 {
631- return ! HasSuperTypeNotInSource ( ) ;
606+ return true ;
632607 }
633608
634- return true ;
609+ if ( effectiveFlags . HasFlagFast ( BindingFlags . DeclaredOnly ) )
610+ {
611+ return type . Locations . Any ( x => x . IsInSource ) ;
612+ }
635613
636- bool HasSuperTypeNotInSource ( )
614+ var current = type ;
615+ while ( current != null &&
616+ current != KnownSymbol . Object )
637617 {
638- var current = type ;
639- while ( current != null &&
640- current != KnownSymbol . Object )
618+ if ( ! current . Locations . Any ( x => x . IsInSource ) )
641619 {
642- if ( ! current . Locations . Any ( x => x . IsInSource ) )
643- {
644- return true ;
645- }
646-
647- current = current . BaseType ;
620+ return false ;
648621 }
649622
650- return false ;
623+ current = current . BaseType ;
651624 }
625+
626+ return true ;
652627 }
653628
654629 private static bool TryGetTargetType ( ExpressionSyntax expression , SyntaxNodeAnalysisContext context , PooledSet < ExpressionSyntax > visited , out ITypeSymbol result , out Optional < IdentifierNameSyntax > instance )
0 commit comments