Skip to content

"Generate Method" for an event handler doesn't add nullability annotation #39693

@Tragetaschen

Description

@Tragetaschen

Version Used:
16.3.7 / 16.4.0 Preview 3.0

Steps to Reproduce:

#nullable enable
using System;
public class Test
{
    private event EventHandler<EventArgs>? myEvent;

    public void M() => myEvent += handler; // Run "Generate Method" here
}

Run the "Generate Method" quick fix for handler and note the nullability annotation on the sender parameter.

Expected Behavior:

+    private void handler(object? sender, EventArgs e) => throw new NotImplementedException();

To match the EventHandler delegate, sender should be typed object?.

Actual Behavior:

+    private void handler(object sender, EventArgs e) => throw new NotImplementedException();

The sender parameter is missing the nullable annotation resulting in an immediate warning.

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions