Why doesn't this work and how do I make it work? In this case M directly implements IMessage and I get a InvalidCastException.
public void Subscribe<M>(IMessageListener<M> listener) where M : IMessage
{
IMessageListener<IMessage> l = (IMessageListener<IMessage>)listener;
}
Shouldn't casting IMessageListener<M>
to IMessageListener<IMessage>
work when M
implements IMessage
?
Sorry for the bad title, didn't know how to describe it.
//EDIT The IMessageListener class looks like this:
public interface IMessageListener<M> where M : IMessage
{
void ProcessMessage(M message);
}