If I have the below code, should I just call the Action or should it call Action.Invoke?
public class ClassA
{
public event Action OnAdd;
Something I noticed on this with the latest C# 6 release as it may encourage Invoke to be used more and thought I'd add it to this old question in case it helps someone:
"Old" way:
Action doSomething = null; // or not null
if (doSomething != null)
doSomething("test");
Possible pragmatic way (similar to empty event delegate pattern):
Action doSomethingPragmatic = s => { }; // empty - might be overwritten later
doSomethingPragmatic("test");
C# 6:
Action doSomethingCs6 = null; // or not null
doSomethingCs6?.Invoke("test");
// Not valid C#:
// doSomethingCs6?("test")
// doSomethingCs6?.("test")