I have one generic interface in c#, and almost always I use it with one of the types. I want to create a non-generic interface for that type and use it.
Let's say, I've the following code:
public interface IMyGenericList<out T> where T : IItem
{
IEnumerable<T> GetList();
}
public class MyList<T> : IMyGenericList<T> where T : IItem
{
public IEnumerable<T> GetList()
{
return null;
}
}
it works well. Most times I need IMyGenericList<IItem>
, so i try the following:
public interface IMyItemsList : IMyGenericList<IItem>
{
}
but I can't make MyList implement IMyItemsList for some reason. The following code returns an error
public class MyList<T> : IMyItemsList, IMyGenericList<T> where T : IItem
{
public IEnumerable<T> GetList()
{
return null;
}
}
saying that IEnumerable<IItem> is not implemented
.
Why is it so/what can I do with this? Thanks.
Ok, thanks to your answers I figured out it's impossible to do it exactly as I wanted initially. I will post another question on why this is impossible :) Here it is: http://stackoverflow.com/questions/4049702/one-function-implementing-generic-and-non-generic-interface