Hello all -
I am having an issue trying to implement a generic interface. Essentially, I have several objects in my library that I need to be able to save their state. So, I created an interface to carry this out. The pertinent bits look like this:
So that any user can just call to an implementer and say "Hey, give me all of my objects" and a list of those objects will be returned.
My problem is coming when I go to implement the interface. I must be missing something on how to use generics properly in this situation. An example implementer looks like this:
The compiler is telling me that I:
"Cannot implicitly convert type 'System.Collections.Generic.List<Cmi.Tabulation.IStateSaver>' to 'System.Collections.Generic.List<T>"
Ok, I understand what the message is telling me, but I've used a conditional that says T must be an IStateSaver. So what gives?
What fundamental piece of knowledge am I missing here?
Any input greatly appreciated.
Thanks,
-paul
The answer to getting answered -- faq855-2992
I am having an issue trying to implement a generic interface. Essentially, I have several objects in my library that I need to be able to save their state. So, I created an interface to carry this out. The pertinent bits look like this:
Code:
public interface IStateSaver
{
...
List<T> GetSavedItems<T>(IPrincipal p_User) where T : IStateSaver;
...
}
My problem is coming when I go to implement the interface. I must be missing something on how to use generics properly in this situation. An example implementer looks like this:
Code:
public class Options : IStateSaver
{
...
public List<T> GetSavedItems<T>(IPrincipal p_User) where T : IStateSaver
{
List<IStateSaver> output = new List<IStateSaver>();
...
//list population goes here
...
return output;
}
...
}
"Cannot implicitly convert type 'System.Collections.Generic.List<Cmi.Tabulation.IStateSaver>' to 'System.Collections.Generic.List<T>"
Ok, I understand what the message is telling me, but I've used a conditional that says T must be an IStateSaver. So what gives?
What fundamental piece of knowledge am I missing here?
Any input greatly appreciated.
Thanks,
-paul
The answer to getting answered -- faq855-2992