Skip to content

C# 14: Support for partial event declarations.#21325

Open
michaelnebel wants to merge 5 commits intogithub:mainfrom
michaelnebel:csharp14/partialmembers
Open

C# 14: Support for partial event declarations.#21325
michaelnebel wants to merge 5 commits intogithub:mainfrom
michaelnebel:csharp14/partialmembers

Conversation

@michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Feb 13, 2026

In this PR we make support for partial event declarations.

That is, we support event declarations like.

public partial class Partial
{
    public partial event EventHandler MyEvent;
}

public partial class Partial
{
    public partial event EventHandler MyEvent {
        add { ... } 
        remove { ... } 
    }
}

The default add/remove event accessors from the declaring declaration are not extracted. Only the explicit add/remove from the implementation declaration are extracted. Note that a partial event always need to have an implementation declaration.

@github-actions github-actions bot added the C# label Feb 13, 2026
@michaelnebel michaelnebel force-pushed the csharp14/partialmembers branch from a37011f to c29bac2 Compare February 16, 2026 15:13
@michaelnebel michaelnebel changed the title C#: Support for partial constructor- and event declarations. C#: Support for partial event declarations. Feb 16, 2026
@michaelnebel michaelnebel changed the title C#: Support for partial event declarations. C# 14: Support for partial event declarations. Feb 16, 2026
@michaelnebel
Copy link
Contributor Author

DCA looks good

  • Performance is unaffected.
  • It looks like the only project that is impacted is dotnet/msbuild, which now has fewer extraction errors.

@michaelnebel michaelnebel marked this pull request as ready for review February 17, 2026 06:52
@michaelnebel michaelnebel requested a review from a team as a code owner February 17, 2026 06:52
Copilot AI review requested due to automatic review settings February 17, 2026 06:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for C# 14 partial event declarations by ensuring that only accessors from the implementation declaration are extracted, not from the declaring declaration. The implementation follows the established pattern used for partial properties and indexers.

Changes:

  • Added extractor support for partial events using BodyDeclaringSymbol pattern (similar to partial properties/indexers)
  • Added NeedsPopulation override in EventAccessor to skip extraction of accessors from partial declaring declarations
  • Added comprehensive test coverage for partial events including AST, accessor detection, and dispatch tests

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
csharp/extractor/Semmle.Extraction.CSharp/Entities/Event.cs Implements BodyDeclaringSymbol and ReportingLocation to use implementation part for partial events; gets accessors from implementation declaration only; modernizes null check pattern
csharp/extractor/Semmle.Extraction.CSharp/Entities/EventAccessor.cs Overrides NeedsPopulation to skip extraction of accessors from partial declaring declarations
csharp/ql/test/library-tests/partial/Partial.cs Adds test cases for partial event declarations
csharp/ql/test/library-tests/partial/PartialEvents.ql New query to test isPartial() predicate on events
csharp/ql/test/library-tests/partial/PartialEvents.expected Expected output for partial events test
csharp/ql/test/library-tests/partial/PartialAccessors.expected Updated to include partial event accessors
csharp/ql/test/library-tests/partial/Partial1.expected Updated with partial event entries
csharp/ql/test/library-tests/partial/PrintAst.expected Updated AST output showing partial event structure
csharp/ql/test/library-tests/partial/PartialProperties.expected Line number updates due to added code
csharp/ql/test/library-tests/partial/PartialMethodBody.expected Line number updates due to added code
csharp/ql/test/library-tests/partial/PartialIndexers.expected Line number updates due to added code
csharp/ql/test/library-tests/partial/PartialConstructors.expected Line number updates due to added code
csharp/ql/test/library-tests/partial/Partial2.expected Line number updates due to added code
csharp/ql/test/library-tests/partial/MethodIsPartial.expected Line number updates due to added code
csharp/ql/test/library-tests/dispatch/ViableCallable.cs Adds test cases for partial event dispatch
csharp/ql/test/library-tests/dispatch/GetADynamicTarget.expected Updated with partial event accessor dispatch targets
csharp/ql/test/library-tests/dispatch/CallGraph.expected Updated call graph with partial event accessors
csharp/ql/lib/change-notes/2026-02-16-partial-events.md Change note documenting C# 14 partial events support

@michaelnebel michaelnebel requested a review from hvitved February 17, 2026 07:07
@michaelnebel michaelnebel changed the title C# 14: Support for partial event declarations. C# 14: Support for partial event declarations. Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant