Creating a generic container, and inner type, using Reflection
May 26, 2010
Type t = Type.GetType(outer_type);
if (t == null)
{
srt.LogClient.Log(Tools.LogLevel.Error, "Failed to instantiate type {0}", outer_type);
return;
}
if (t.IsGenericType == true)
{
Type[] innerTArr = t.GetGenericArguments();
if (innerTArr == null || innerTArr.Length == 0)
{
Log("inner Type was not found. Cannot instantiate a generic class");
return;
}
Type innerT = innerTArr[0];
Type genericType = t.GetGenericTypeDefinition();
Type[] typeArgs = { innerT };
Type constructed = genericType.MakeGenericType(typeArgs);
object o = Activator.CreateInstance(constructed);
mac = o as IMac;
}