Events of a non-delegate type

前端 未结 4 412
一生所求
一生所求 2021-01-03 03:27

I\'ve implemented a class that looks like this interface:

[ImmutableObject(true)]
public interface ICustomEvent
{
    void Invoke(object sender, EventArgs e)         


        
4条回答
  •  一整个雨季
    2021-01-03 04:04

    Try this:

    CustomEvent myEvent
    
    public event EventHandler MyEvent {
        add { myEvent = myEvent.Combine(value); }
        remove {myEvent = myEvent.Remove(value); }
    }
    

    You can add and remove normal EventHandler delegates to it, and it will execute the add and remove accessors.


    EDIT: You can find a weak event implementation here.
    2nd EDIT: Or here.

提交回复
热议问题