I would like to write the following method
private void Foo<T, TItem>(T<TItem> param1)
Where T must be a generic type that accepts a TItem as its generic information.
Call example:
private void Main() { List<int> ints = new List<int>(); Foo<List, int>(ints); }
Edit: In my case, I only needed for collections. The actual use case is that I wanted to write a method that adds something to ICollection, unfortunately ICollection does not have a .Add method that only has ICollection<T> .
I can not change the method:
private Foo<T>(ICollection<T>)
since with this I am losing information about what type is the actual list, which is more important to me than what type of items are in the list.
therefore, the above idea came up, which did not work.
source share