Given the following interfaces, I don't understand why the second method defined on ITransactionConsumer will not compile. The compiler complains that it is not convertable to ITransaction<IUser> - but there is a generic constraint that TUser is an IUser..?
public interface ITransactionConsumer
{
//fine
PaymentSession<TTransaction> ConsumeTransaction<TTransaction>( TTransaction transaction )
where TTransaction : ITransaction<IUser>;
//compile error - TTransaction is not convertable to ITransaction<IUser>
PaymentSession<TTransaction> ConsumeTransactionWithTUser<TTransaction, TUser>(TTransaction transaction)
where TTransaction : ITransaction<TUser> where TUser : IUser;
}
public class PaymentSession<TTransaction>
where TTransaction : ITransaction<IUser>
{
}
public interface ITransaction<out TUser>
where TUser : IUser
{
TUser User { get; }
string Id { get; }
}
public interface IUser
{
string Name { get; }
}
TUser, i.e.where TUser class, IUser.