views:

94

answers:

4

Is there a .NET framework interface like this?

public interface IEvent
{
    event EventHandler Event;
}

I can of course write my own, but I'll reuse it if it already exists. Could perhaps have a Fire/Raise method on it too.

+9  A: 

No there is not.

Typically events in C# / CLR do not use an interface base pattern as shown in your question. This is much more akin to the Java style of eventing. The closest item would be a generic event delegate which can be re-used instead of creating new delegate types. This does exist in System.EventHandler<TEventArgs>

JaredPar
+1, you're right, it does look very familiar to Java's observer style (though backwards)
Adam Robinson
A: 

No, there is no such standard interface in the BCL or any other .NET class libraries, at least as far as I am aware.

Adam Robinson
A: 

There's no real match to this in the .NET world. Can I suggest though, that you look into an implementation of the EventPool? This has the ability to fire events, and the events can be described as enums (or the like).

Pete OHanlon
+2  A: 

Not yet, but there will be in .Net 4.0, IObservable<T> and IObserver<T> interfaces part of the Reactive Framework, see info on Paul Batum blog.

This is how the interfaces are in their current incarnation:

interface IObservable<out T> 
{      
    IDisposable Subscribe(IObserver o); 
} 

interface IObserver<in T>  
{     
    void OnCompleted();     
    void OnNext(T v);      
    void OnError(Exception e); 
}
Pop Catalin
I was going to mention it. Very interesting will probably be as common as IEnumerable<T> soon enough.
Richard Hein