PEK
PEK

Reputation: 4318

How to I solve CA1009-warnings (declare event handlers correctly) with TypedEventHandler?

In an UWP application I have a class like this:

public class MyClass
{
    public event TypedEventHandler<MyClass, EventArgs> MyEvent;
}

When I run code analysis this code gives me two warnings:

CA1009 Declare the second parameter of 'TypedEventHandler' as an EventArgs, or an instance of a type that extends EventArgs, named 'e'.

CA1009 Declare the first parameter of 'TypedEventHandler' as an object named 'sender'.

How do I solve these issues? I've read the documentation about CA1009 but it doesn't give me any hint.

Upvotes: 0

Views: 476

Answers (1)

Peter Torr
Peter Torr

Reputation: 12019

For the classic .NET pattern, your class should derive from EventArgs to fix the first warning, although that won't work for a Windows Runtime component. You should just ignore the warning.

For the classic .NET pattern, the first type should be Object but for newer designs (like WinRT) you should also ignore the second warning.

Upvotes: 1

Related Questions