I'm trying to take an existing type (in the form of an object) and derive a
"type" from it that can be passed to generic method.

You mean like this?

// from an Type...
public IList MakeList(Type instanceType)
{
Type genericType = typeof(List<>);
Type closedType = genericType.MakeGenericType(instanceType);
return Activator.CreateInstance(closedType,
BindingFlags.CreateInstance | BindingFlags.NonPublic |
BindingFlags.Instance, null, null, null, null);
}

// from an instance of a Type...
public IList MakeList(object thing)
{
Type instanceType = thing.GetType();
return MakeList(instanceType);
}

// from a Type name
public IList MakeList(string typeName)
{
Type instanceType = Type.GetType(typeName, false, true);
return MakeList(instanceType);
}

--
"One of the main causes of the fall of the Roman Empire was that,
lacking zero, they had no way to indicate successful termination of
their C programs." --Robert Firth

Marc C. Brooks
http://musingmarc.blogspot.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to