interface IMyEvent { }
class SpecificEvent : IMyEvent { }
interface IMySubscriber<TEvent> where TEvent : IMyEvent { }
class MySubscriber<TEvent> : IMySubscriber<TEvent> where TEvent: IMyEvent { }
class EventPublisher
{
public void Subscribe(IMySubscriber<IMyEvent> subscriber)
{
}
}
I can't understand why it's impossible to execute Subscribe method with a MySubscriber<SpecificEvent>
object.
new EventPublisher().Subscribe(new MySubscriber<SpecificEvent>());
It says that it can't cast MySubscriber<SpecificEvent>
to IMySubscriber<IMyEvent>
. Could you please explain why it happens or provide some links where I can read about it.