I have a method with the following signature:
public IDisposable RegisterSubscriber<T>(T subscriber)
where T : MessageBusSubscriber<IMessageBusEvent>
{
}
I am trying to call this from a MessageBusSubscriber<MoveEvent>
:
public class MoveSubscriber : MessageBusSubscriber<MoveEvent>
{
private readonly IDisposable _subscription;
public MoveSubscriber(MessageBus bus)
{
_subscription = bus.RegisterSubscriber(this);
}
}
public class MoveEvent : IMessageBusEvent {}
public interface IMessageBusEvent { }
I get the following error: CS0311 The type 'MoveSubscriber' cannot be used as type parameter 'T' in the generic type or method 'MessageBus.RegisterSubscriber<T>(T)'. There is no implicit reference conversion from 'MoveSubscriber' to 'MessageBusSubscriber<IMessageBusEvent>'.
Am I missing something or should this work, I was under the impression that a class that uses a generic restricted to a certain interface should allow a class that implements said interface in it's place.
e.g A MessageBusSubscriber<MoveEvent>
is a MessageBusSubscriber<IMessageBusEvent>
so should be allowed.
Thanks