@@ -182,7 +182,7 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
182
182
if ( member == null )
183
183
{
184
184
member = candidate ;
185
- if ( IsOfWrongType ( member ) )
185
+ if ( IsWrongMemberType ( member ) )
186
186
{
187
187
return GetXResult . WrongMemberType ;
188
188
}
@@ -200,15 +200,7 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
200
200
201
201
if ( targetType . TryFindFirstMemberRecursive ( name , out member ) )
202
202
{
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 ) )
212
204
{
213
205
return GetXResult . UseContainingType ;
214
206
}
@@ -251,12 +243,15 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
251
243
continue ;
252
244
}
253
245
246
+ if ( IsOverriding ( member , candidate ) )
247
+ {
248
+ continue ;
249
+ }
250
+
254
251
if ( member == null )
255
252
{
256
253
member = candidate ;
257
- if ( member . IsStatic &&
258
- member . DeclaredAccessibility == Accessibility . Private &&
259
- ! member . ContainingType . Equals ( targetType ) )
254
+ if ( IsUseContainingType ( member ) )
260
255
{
261
256
return GetXResult . UseContainingType ;
262
257
}
@@ -268,15 +263,11 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
268
263
return GetXResult . WrongFlags ;
269
264
}
270
265
271
- if ( IsOfWrongType ( candidate ) )
266
+ if ( IsWrongMemberType ( candidate ) )
272
267
{
273
268
return GetXResult . WrongMemberType ;
274
269
}
275
270
}
276
- else if ( IsOverriding ( member , candidate ) )
277
- {
278
- // continue
279
- }
280
271
else
281
272
{
282
273
return GetXResult . Ambiguous ;
@@ -312,34 +303,34 @@ internal static GetXResult TryGetMember(IMethodSymbol getX, ITypeSymbol targetTy
312
303
313
304
return GetXResult . Single ;
314
305
315
- bool IsOfWrongType ( ISymbol candidate )
306
+ bool IsWrongMemberType ( ISymbol symbol )
316
307
{
317
308
if ( getX . ReturnType == KnownSymbol . EventInfo &&
318
- ! ( candidate is IEventSymbol ) )
309
+ ! ( symbol is IEventSymbol ) )
319
310
{
320
311
return true ;
321
312
}
322
313
323
314
if ( getX . ReturnType == KnownSymbol . FieldInfo &&
324
- ! ( candidate is IFieldSymbol ) )
315
+ ! ( symbol is IFieldSymbol ) )
325
316
{
326
317
return true ;
327
318
}
328
319
329
320
if ( getX . ReturnType == KnownSymbol . MethodInfo &&
330
- ! ( candidate is IMethodSymbol ) )
321
+ ! ( symbol is IMethodSymbol ) )
331
322
{
332
323
return true ;
333
324
}
334
325
335
326
if ( getX . ReturnType == KnownSymbol . PropertyInfo &&
336
- ! ( candidate is IPropertySymbol ) )
327
+ ! ( symbol is IPropertySymbol ) )
337
328
{
338
329
return true ;
339
330
}
340
331
341
332
if ( getX . ReturnType == KnownSymbol . Type &&
342
- ! ( candidate is ITypeSymbol ) )
333
+ ! ( symbol is ITypeSymbol ) )
343
334
{
344
335
return true ;
345
336
}
@@ -349,6 +340,11 @@ bool IsOfWrongType(ISymbol candidate)
349
340
350
341
bool IsOverriding ( ISymbol symbol , ISymbol candidateBase )
351
342
{
343
+ if ( symbol == null )
344
+ {
345
+ return false ;
346
+ }
347
+
352
348
if ( symbol . IsOverride )
353
349
{
354
350
switch ( symbol )
@@ -368,6 +364,14 @@ bool IsOverriding(ISymbol symbol, ISymbol candidateBase)
368
364
return false ;
369
365
}
370
366
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
+
371
375
bool IsExplicitImplementation ( out ISymbol result )
372
376
{
373
377
foreach ( var @interface in targetType . AllInterfaces )
0 commit comments