Reputation: 2241
Basically, I want to write a wrapper for all ICollection<> types. Lets call it DelayedAddCollection. It should take any ICollection as its .
Furthermore, I need access to that ICollection type's generic type as the Add method needs to restrict its parameter to that type.
The syntax I would imagine would look something like this...
public DelayedAddConnection<T>: where T:ICollection<U> {
....
public void Add(U element){
...
}
}
What is the real correct syntax to do this?
Upvotes: 9
Views: 181
Reputation: 2241
So, for future reference the final, cleanest version of this idea I implemented thanks to all the suggestions and comments was this:
public class DelayedUpdateCollection<U>: ICollection<U>
{
ICollection<U> collection;
public DelayedUpdateCollection(ICollection<U> coll){
collection = coll;
}
...
Upvotes: 0
Reputation: 144206
You need to add another generic type parameter:
public class DelayedAddConnection<T, U> where T : ICollection<U>
{
}
Upvotes: 17