How do I create a new delegate type based on an existing one, in C#?

前端 未结 4 1526
温柔的废话
温柔的废话 2021-02-12 21:46

Is there any way that I can create a new delegate type based on an existing one? In my case, I\'d like to create a delegate MyMouseEventDelegate which would have th

4条回答
  •  终归单人心
    2021-02-12 22:12

    I you only want to achieve compile time type checking I guess it would be enough to create specialized EventArgs classes for the cases that you describe. That way you can still take advantage of the pre-defined delegates:

    class RightMouseButtonEventArgs : MouseEventArgs {}
    class LeftMouseButtonEventArgs : MouseEventArgs {}
    
    EventHandler
    EventHandler
    

提交回复
热议问题