T newObject = new T();
Yes! I finally figured out the solution to a long-time problem of mine!
Okay, suppose you're using generics in C#...
public class AwesomeClass<T> where T : IList<T>
{
// ....
}
...and in one of the methods, you want to create a new object of type T, in this case a new IList-derived class.
I banged my head a lot and was doing crazy stuff with reflection until like two days ago when I accidentally stumbled upon finally read the MSDN documentation on type constraints and found that to be able to write
T newCollection = new T()
all I needed to do was add a little something to the class declaration:
public class AwesomeClass<T> where T : IList<T>, new()