Skip to content

Commit 1b05791

Browse files
committed
C#: Support for partial event declarations.
1 parent 233e8e9 commit 1b05791

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Event.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ internal class Event : CachedSymbol<IEventSymbol>
1111
private Event(Context cx, IEventSymbol init)
1212
: base(cx, init) { }
1313

14+
protected override IEventSymbol BodyDeclaringSymbol => Symbol.PartialImplementationPart ?? Symbol;
15+
16+
public override Microsoft.CodeAnalysis.Location? ReportingLocation => BodyDeclaringSymbol.Locations.BestOrDefault();
17+
1418
public override void WriteId(EscapingTextWriter trapFile)
1519
{
1620
trapFile.WriteSubId(ContainingType!);
@@ -27,13 +31,13 @@ public override void Populate(TextWriter trapFile)
2731
var type = Type.Create(Context, Symbol.Type);
2832
trapFile.events(this, Symbol.GetName(), ContainingType!, type.TypeRef, Create(Context, Symbol.OriginalDefinition));
2933

30-
var adder = Symbol.AddMethod;
31-
var remover = Symbol.RemoveMethod;
34+
var adder = BodyDeclaringSymbol.AddMethod;
35+
var remover = BodyDeclaringSymbol.RemoveMethod;
3236

33-
if (!(adder is null))
37+
if (adder is not null)
3438
Method.Create(Context, adder);
3539

36-
if (!(remover is null))
40+
if (remover is not null)
3741
Method.Create(Context, remover);
3842

3943
PopulateModifiers(trapFile);

csharp/extractor/Semmle.Extraction.CSharp/Entities/EventAccessor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ private EventAccessor(Context cx, IMethodSymbol init, IEventSymbol @event)
1313
this.@event = @event;
1414
}
1515

16+
public override bool NeedsPopulation =>
17+
base.NeedsPopulation &&
18+
!Symbol.IsPartialDefinition; // Accessors always have an implementing declaration as well.
19+
1620
/// <summary>
1721
/// Gets the event symbol associated with accessor `symbol`, or `null`
1822
/// if there is no associated symbol.

0 commit comments

Comments
 (0)