Mark Heath
Mark Heath

Reputation: 49482

Is there a standard interface in .NET containing a single EventHandler

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.

Upvotes: 1

Views: 284

Answers (4)

Pop Catalin
Pop Catalin

Reputation: 62950

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); 
}  

Upvotes: 2

Pete OHanlon
Pete OHanlon

Reputation: 9146

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).

Upvotes: 0

Adam Robinson
Adam Robinson

Reputation: 185643

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

Upvotes: 0

JaredPar
JaredPar

Reputation: 754763

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>

Upvotes: 9

Related Questions