I am trying to create a generic typed class, but am running into a problem. Here is my basic class definition:
public class QueueObject<T> where T : System.ServiceModel.DomainServices.Client.Entity
{
public string LoadingMessage { get; set; }
public System.ServiceModel.DomainServices.Client.EntityQuery<T> Query { get; set; }
}
I am trying to add instances of this class to a queue
private Queue<QueueObject<Entity>> _queue;
this._queue.Enqueue(new QueueObject<MyEntity> {Query = MyContext.GetMyEntitiesQuery(), LoadingMessage = "Loading some stuff"});
This doesn't work. I get an error saying that QueueObject cannont be converted to QueueObject. I don't understand because MyEntity inherits from Entity. Am I doing something wrong?
Here is the same code in VB if it helps:
Public Class QueueObject(Of T As System.ServiceModel.DomainServices.Client.Entity)
Public Property LoadingMessage As String
Public Property Query As System.ServiceModel.DomainServices.Client.EntityQuery(Of T)
End Class
Private _queue As Queue(QueueObject(Of Entity))
Me._queue.Enqueue(New QueueObject(Of MyEntity) With {.Query = MyContext.GetMyEntitiesQuery(), .LoadingMessage = "Loading some stuff..."})
Still not sure about the reason for the original error, but a possible solution was to make each entity implement an interface. Then make the QueueObject be of this interface type.
I ended up going another route so this ended up being irrelevant.