@@ -182,7 +182,7 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
182182 if ( member == null )
183183 {
184184 member = candidate ;
185- if ( IsOfWrongType ( member ) )
185+ if ( IsWrongMemberType ( member ) )
186186 {
187187 return GetXResult . WrongMemberType ;
188188 }
@@ -200,15 +200,7 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
200200
201201 if ( targetType . TryFindFirstMemberRecursive ( name , out member ) )
202202 {
203- if ( getX == KnownSymbol . Type . GetNestedType &&
204- ! targetType . Equals ( member . ContainingType ) )
205- {
206- return GetXResult . UseContainingType ;
207- }
208-
209- if ( member . IsStatic &&
210- member . DeclaredAccessibility == Accessibility . Private &&
211- ! targetType . Equals ( member . ContainingType ) )
203+ if ( IsUseContainingType ( member ) )
212204 {
213205 return GetXResult . UseContainingType ;
214206 }
@@ -251,12 +243,15 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
251243 continue ;
252244 }
253245
246+ if ( IsOverriding ( member , candidate ) )
247+ {
248+ continue ;
249+ }
250+
254251 if ( member == null )
255252 {
256253 member = candidate ;
257- if ( member . IsStatic &&
258- member . DeclaredAccessibility == Accessibility . Private &&
259- ! member . ContainingType . Equals ( targetType ) )
254+ if ( IsUseContainingType ( member ) )
260255 {
261256 return GetXResult . UseContainingType ;
262257 }
@@ -268,15 +263,11 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
268263 return GetXResult . WrongFlags ;
269264 }
270265
271- if ( IsOfWrongType ( candidate ) )
266+ if ( IsWrongMemberType ( candidate ) )
272267 {
273268 return GetXResult . WrongMemberType ;
274269 }
275270 }
276- else if ( IsOverriding ( member , candidate ) )
277- {
278- // continue
279- }
280271 else
281272 {
282273 return GetXResult . Ambiguous ;
@@ -312,34 +303,34 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
312303
313304 return GetXResult . Single ;
314305
315- bool IsOfWrongType ( ISymbol candidate )
306+ bool IsWrongMemberType ( ISymbol symbol )
316307 {
317308 if ( getX . ReturnType == KnownSymbol . EventInfo &&
318- ! ( candidate is IEventSymbol ) )
309+ ! ( symbol is IEventSymbol ) )
319310 {
320311 return true ;
321312 }
322313
323314 if ( getX . ReturnType == KnownSymbol . FieldInfo &&
324- ! ( candidate is IFieldSymbol ) )
315+ ! ( symbol is IFieldSymbol ) )
325316 {
326317 return true ;
327318 }
328319
329320 if ( getX . ReturnType == KnownSymbol . MethodInfo &&
330- ! ( candidate is IMethodSymbol ) )
321+ ! ( symbol is IMethodSymbol ) )
331322 {
332323 return true ;
333324 }
334325
335326 if ( getX . ReturnType == KnownSymbol . PropertyInfo &&
336- ! ( candidate is IPropertySymbol ) )
327+ ! ( symbol is IPropertySymbol ) )
337328 {
338329 return true ;
339330 }
340331
341332 if ( getX . ReturnType == KnownSymbol . Type &&
342- ! ( candidate is ITypeSymbol ) )
333+ ! ( symbol is ITypeSymbol ) )
343334 {
344335 return true ;
345336 }
@@ -349,6 +340,11 @@ bool IsOfWrongType(ISymbol candidate)
349340
350341 bool IsOverriding ( ISymbol symbol , ISymbol candidateBase )
351342 {
343+ if ( symbol == null )
344+ {
345+ return false ;
346+ }
347+
352348 if ( symbol . IsOverride )
353349 {
354350 switch ( symbol )
@@ -368,6 +364,14 @@ bool IsOverriding(ISymbol symbol, ISymbol candidateBase)
368364 return false ;
369365 }
370366
367+ bool IsUseContainingType ( ISymbol symbol )
368+ {
369+ return ! targetType . Equals ( symbol . ContainingType ) &&
370+ ( getX == KnownSymbol . Type . GetNestedType ||
371+ ( symbol . IsStatic &&
372+ symbol . DeclaredAccessibility == Accessibility . Private ) ) ;
373+ }
374+
371375 bool IsExplicitImplementation ( out ISymbol result )
372376 {
373377 foreach ( var @interface in targetType . AllInterfaces )
0 commit comments