How can I write a generic container class that implements a given interface in C#?
This isn’t pretty, but it seems to work: public static class GroupGenerator { public static T Create<T>(IEnumerable<T> items) where T : class { return (T)Activator.CreateInstance(Cache<T>.Type, items); } private static class Cache<T> where T : class { internal static readonly Type Type; static Cache() { if (!typeof(T).IsInterface) { throw new InvalidOperationException(typeof(T).Name + ” is not an … Read more