VSDiagnostics icon indicating copy to clipboard operation
VSDiagnostics copied to clipboard

Implement EventHandlerWithInlineLambdaAssignment

Open Vannevelj opened this issue 8 years ago • 0 comments

Assigning a lambda inline to an event handler essentially makes sure that it can never be removed from that event handler. This article goes deeper into the subject.

An example analyzer that warns for this can be found here.

I suggest we just do the same thing: show a warning when this situation occurs (both for -= and +=). Example:

myEvent += (,) => Console.WriteLine(); // "Don't assign an inline lambda to an event handler since it can never be removed"
myEvent -= (,) => Console.WriteLine(); // "An inline lambda cannot be removed as an event handler"

Notice how we have two different messages depending on the situation to make it clear that the -= is a no-op.

Vannevelj avatar May 31 '16 12:05 Vannevelj