Is calling an extension method on a “null” reference (i.e. event with no subscribers) evil?

前端 未结 8 724
梦谈多话
梦谈多话 2020-12-12 16:05

Evil or not evil?

public static void Raise(this EventHandler handler, object sender, EventArgs args)
{
   if (handler != null)
   {
      handler(sender, arg         


        
8条回答
  •  庸人自扰
    2020-12-12 16:47

    I wouldn't say it's evil, but I'm interested in how your extension method fits in with the

    protected virtual OnSomeEvent(EventArgs e){ }
    

    pattern and how it handles extensibility via inheritance. Does it presume all subclasses will handle the event instead of override a method?

提交回复
热议问题