|
7 | 7 | using System.ComponentModel;
|
8 | 8 | using System.Diagnostics.Contracts;
|
9 | 9 | using System.Linq;
|
10 |
| -using Microsoft.Cci; |
| 10 | +using Microsoft.Cci.Extensions.CSharp; |
11 | 11 |
|
12 | 12 | namespace Microsoft.Cci.Extensions
|
13 | 13 | {
|
@@ -490,24 +490,27 @@ public static bool IsPropertyOrEventAccessor(this IMethodDefinition method)
|
490 | 490 | public static AccessorType GetAccessorType(this IMethodDefinition methodDefinition)
|
491 | 491 | {
|
492 | 492 | if (!methodDefinition.IsSpecialName)
|
| 493 | + { |
493 | 494 | return AccessorType.None;
|
| 495 | + } |
494 | 496 |
|
495 |
| - foreach (var p in methodDefinition.ContainingTypeDefinition.Properties) |
| 497 | + // Cannot use MemberHelper.IsAdder(...) and similar due to their TypeMemberVisibility.Public restriction. |
| 498 | + var name = methodDefinition.GetNameWithoutExplicitType(); |
| 499 | + if (name.StartsWith("add_")) |
496 | 500 | {
|
497 |
| - if (p.Getter != null && p.Getter.ResolvedMethod.InternedKey == methodDefinition.InternedKey) |
498 |
| - return AccessorType.PropertyGetter; |
499 |
| - |
500 |
| - if (p.Setter != null && p.Setter.ResolvedMethod.InternedKey == methodDefinition.InternedKey) |
501 |
| - return AccessorType.PropertySetter; |
| 501 | + return AccessorType.EventAdder; |
502 | 502 | }
|
503 |
| - |
504 |
| - foreach (var e in methodDefinition.ContainingTypeDefinition.Events) |
| 503 | + else if (name.StartsWith("get_")) |
505 | 504 | {
|
506 |
| - if (e.Adder != null && e.Adder.ResolvedMethod.InternedKey == methodDefinition.InternedKey) |
507 |
| - return AccessorType.EventAdder; |
508 |
| - |
509 |
| - if (e.Remover != null && e.Remover.ResolvedMethod.InternedKey == methodDefinition.InternedKey) |
510 |
| - return AccessorType.EventRemover; |
| 505 | + return AccessorType.PropertyGetter; |
| 506 | + } |
| 507 | + else if (name.StartsWith("remove_")) |
| 508 | + { |
| 509 | + return AccessorType.EventRemover; |
| 510 | + } |
| 511 | + else if (name.StartsWith("set_")) |
| 512 | + { |
| 513 | + return AccessorType.PropertySetter; |
511 | 514 | }
|
512 | 515 |
|
513 | 516 | return AccessorType.None;
|
|
0 commit comments