How can I work with explicit interface events?

So, I made several such interfaces:

public interface IDrawActions : ISimpleDrawable
{
    Action<GameTime> PreDrawAction { get; set; }
    Action<GameTime> PostDrawAction { get; set; }

    event EventHandler PreDrawActionChanged;
    event EventHandler PostDrawActionChanged;
}

Any classes that implement this (or several) of these interfaces have become messy, so I thought it made sense to use an explicit implementation of the interface to hide unusual events and properties. But doing this, I got a compiler error:

An explicit interface implementation for an event must use event access syntax

And Googling will lead me to this pretty useful blog post :

: . , , , , - , , , . , .

? , , , ? !

+4
1

, , , , , . # event. - :

  • , . . , .
  • , , , . , , "+ =" "- =" .

, #.

. , , , . , .

? , VG.net, Microsoft : . . - . , :

  • . . - , , , , .
  • . ().

, , . , , . , , Delegate.Combine. , Delegate.Remove.

VG.net:

    private static readonly int MouseDownEvent = EventsProperty.CreateEventKey();

    public event ElementMouseEventHandler MouseDown
    {
        add { AddHandler(MouseDownEvent, value); }
        remove { RemoveHandler(MouseDownEvent, value); }
    }

    public virtual void OnMouseDown(ElementMouseEventArgs args)
    {
        ElementMouseEventHandler handler = 
            FindHandler(MouseDownEvent) as ElementMouseEventHandler;
        if (handler != null)
            handler(this, args);
    }

    internal void AddHandler(int key, Delegate value)
    {
        EventsProperty p = (EventsProperty)GetOrInsertProperty(EventsProperty.Key);
        p.AddHandler(key, value);
    }

    internal void RemoveHandler(int key, Delegate value)
    {
        EventsProperty p = (EventsProperty)GetProperty(EventsProperty.Key);
        if (p == null)
            return;
        p.RemoveHandler(key, value);
    }

    internal Delegate FindHandler(int key)
    {
        EventsProperty p = (EventsProperty)GetProperty(EventsProperty.Key);
        if (p == null)
            return null;
        return p[key];
    }

, . VG.net (EventProperty), , , . , , :

  • , .
  • - .

VG.net , , .

, . - , . , , - .

+1

All Articles