私はこれらの定義を持っています:
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;
}
これをコンパイルすると、次のエラーが発生します。
**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>>'.
これは制約の問題ですか?Queue クラスに 2 つのタイプを使用することを考えています。1 つは IHasId を実装するタイプで、もう 1 つは Queueable を実装するタイプですが、実際には解決が簡単になることを願っています。
考え?
前もって感謝します!R.