The simplest thing is just to specify only the type of element and hard code ICollection<T>where you need it, for example
class MyClass<T> {
private ICollection<T> _items;
public MyClass(ICollection<T> items) {
_items = items;
}
public void Store(T obj) {
_items.Add(obj);
}
public ICollection<T> Items {
get {
return _items;
}
}
}
, . "" ( ) , . .
RE-EDIT (3- ): typedef , . , , .
1 - :
class BazAndListOfWrgl {
Baz Baz { get; set; }
List<Wrgl> Wrgls { get; set; }
}
// Simple typedef.
class BazAndListOfWrglDictionary : Dictionary<Bar, BazAndListOfWrgl> { }
2 - . . , , ( ).
using OuterDictionary = System.Collections.Generic.Dictionary<MyNamespace.Foo, MyNamespace.BazAndListOfWrglDictionary>;
using OuterDictionaryItem = System.Collections.Generic.KeyValuePair<MyNamespace.Foo, MyNamespace.BazAndListOfWrglDictionary>;
3 - :
class Program {
static void Main() {
var listWrapper = new MyClass<BazAndListOfWrgl>(new List<BazAndListOfWrgl>());
listWrapper.Store(new BazAndListOfWrgl());
Console.WriteLine(listWrapper.Items.Count);
var dictionaryWrapper = new MyClass<OuterDictionaryItem>(new OuterDictionary());
dictionaryWrapper.Store(new OuterDictionaryItem(new Foo(), new BazAndListOfWrglDictionary()));
Console.WriteLine(dictionaryWrapper.Items.Count);
}
}
: BazAndListOfWrglDictionary , . OuterDictionary OuterDictionaryItem , .