I have these definitions:
public interface IHasId
{
string Id { get; set; }
}
public class Something : IHasId
{
public string Id { get; set; }
}
public class Queueable<T>
where T : IHasId, new()
{
public T Item { get; set; }
public int QueueId { get; set; }
}
public class Queue<T>
where T : Queueable<T>, IHasId, new()
{
public void Enqueue(T item)
{
}
public T Dequeue()
{
return default(T);
}
}
public class QueueService
{
private Queue<Queueable<Something>> queue;
//private Queue<Queueable<SomethingElse>> somethingElseQueue;
}
When I compile this I'm getting these errors:
**Error**: The type 'test.Queueable<test.Something>' cannot be used as type parameter 'T' in the generic type or method 'test.Queue<T>'. There is no implicit reference conversion from 'test.Queueable<test.Something>' to 'test.IHasId'.
**Error**: The type 'test.Queueable<test.Something>' cannot be used as type parameter 'T' in the generic type or method 'test.Queue<T>'. There is no implicit reference conversion from 'test.Queueable<test.Something>' to 'test.Queueable<test.Queueable<test.Something>>'.
Is this a problem of constraints? I'm thinking on using 2 types for the Queue class, one for the one implementing the IHasId and the other for the Queueable but I'm hoping this is actually simpler to resolve.
Thoughts?
Thanks in advance! R.
Queue<T>class?Queueable<T>is notIHasIdjust because itsTis, but yourQueueclass expects it to be.