I have 3 classes: A, B, and C
All of these classes implement an interface IMyInterface
I would like the interface to be defined like so:
internal IMyInterface<E> where E: class
{
E returnData();
}
So that it can return data of type E.
The type “E” will be a POCO object created with the Entity Framework v4.
In a separate class I have:
public class MyClass()
{
IMyInterface<??> businessLogic;
public setBusinessLogic(IMyInterface<E> myObject)
where E : class
{
businessLogic = myObject;
}
}
I tried putting <object> in place of <??> but it could not cast my poco entity type.
I tried having my entities implement an empty interface IEntity then using
IMyInterface<IEntity> businessLogic;
...
businessLogic = new A<POCOObject>();
results in:
Cannot implicitly convert type
'A<POCOObject>' to
'IMyInterface<IEntity>'. An explicit
conversion exists (are you missing a
cast?)
Any recommendations?
Edit: I’ve tried declaring my A, B, and C classes as:
internal class A : IBidManager<EntityObjectType>
and
internal class A<E> : IBidManager<E> where E : class
results in the same error.
It will have to be either
or
If you wnt your business object to handle any POCO object and they each have an interface then you will need to specify
where E : class, IEntityat the class level. Otherwise you have yo use concrete type for the generic arg