Depending on how often you're calling this method then using Activator.CreateInstance could be slow. Another option is to do something like this:
private Dictionary> delegates = new Dictionary>();
public Dictionary GenerateLists(List types)
{
Dictionary lists = new Dictionary();
foreach (Type type in types)
{
if (!delegates.ContainsKey(type))
delegates.Add(type, CreateListDelegate(type));
lists.Add(type, delegates[type]());
}
return lists;
}
private Func
On the first hit it'll create a delegate to the generic method that creates the list and then puts that in a dictionary. On each subsequent hit you'll just call the delegate for that type.
Hope this helps!