Reputation: 16430
E.G
List<Node> myNodeList<node>();
System.Type theType = myNodeList.GetType();
IEnumerable list<theType> = myNodeList;
Upvotes: 1
Views: 617
Reputation: 101150
//original list
List<Node> nodeList = new List<Node>();
// just get the type of the list
var nodeListType = nodeList.GetType();
// Create a new type for a list containing the original list.
var genericType = typeof (List<>).MakeGenericType(nodeListType);
// and instantiate it.
var listOfLists = (IEnumerable)Activator.CreateInstance(genericType);
You could also make a generic version:
public static IList<T> CreateOuterlist<T>(T innerList)
{
return new List<T>();
}
List<Node> nodeList = new List<Node>();
var listOfLists = CreateOuterlist(nodeList);
listOfLists.Add(nodeList);
Upvotes: 3