C# event with custom arguments

前端 未结 7 1536
庸人自扰
庸人自扰 2020-12-05 09:29

I want to have an event that takes an enum only as the argument. For example

public enum MyEvents{
   Event1
}

// how do I declare this to take enum MyEvent         


        
7条回答
  •  我在风中等你
    2020-12-05 09:50

    I might be late in the game, but how about:

    public event Action EventTriggered = delegate { }; 
    
    private void Trigger(MyEvent e) 
    { 
         EventTriggered(e);
    } 
    

    Setting the event to an anonymous delegate avoids for me to check to see if the event isn't null.

    I find this comes in handy when using MVVM, like when using ICommand.CanExecute Method.

提交回复
热议问题