I have a problem that I'm trying to wrap my head around. I might be terribly mistaken but here is what I'm trying to do.
I have two interfaces. The second interfaces has a property that should be of a implementation of the first interface. Something like this:
public interface ITypeA{
int Id {get;set;}
}
public interface IEntityA<T>: where T:ITypeA
{
string Name{get;set;}
T type{get;set;}
}
The implementations looks like this:
public class TypeA: ITypeA{
int Id {get;set;}
}
public class EntityA: IEntityA<TypeA>{
public string Name{get;set;}
public TypeA type{get;set;
}
I might be doing something wrong already(?).
Now I'm implementing the repository pattern, and the interface for that looks like this:
public interface IRepo{
IEnumerable<IEntityA<ITypeA>> GetObjects();
}
and the implementation:
public class DefaultRepo:Repo{
//Cunstructors
public IEnumerable<IEntitytA<ITypeA>> GetObjects(){
var objects = SomeMethodThatReturnsTheOjects();//Get objects as EntityA[];
return object.ToList();
}
}
This doesn't work.
I've tried to cast it as well, but getting a warning that it is a suspicious cast.
objects.Cast<IEntityA<ITypeA>[]>().ToList();
Where am I doing/thinking wrong?
Help much appriciated :)
EDIT: Maybe the repository interface declaration should look like this
public interface IRepo<TEntityA> where TEntityA:IEntityA{
IEnumerable<TEntityA> GetObjects();
}
and the implementation:
public class DefaultRepo:Repo<EntityA>{
///Methods
}
Thoughts?? :)