TypeName | UseInvokeMethodToFireEventAnalyzer |
Check Id | CC0031 |
Category | Design |
Severity | Warning |
In C#6 a delegate can be invoked using the null-propagating operator (?.) and it’s invoke method to avoid throwing a NullReference exception when there is no method attached to the delegate.
public class MyClass
{
public event System.EventHandler MyEvent;
public void Execute()
{
MyEvent(this, System.EventArgs.Empty);
}
}
A code fix will be presented to you that will transform the code:
public class MyClass
{
public event System.EventHandler MyEvent;
public void Execute()
{
MyEvent?.Invoke(this, System.EventArgs.Empty);
}
}
TBD