1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
// aufruf
public void testRun()
{
IList<int> var = new List<int>();
TestMethod(var);
}
public void TestMethod(object var)
{
if (var.GetType().IsGenericType)
{
Type[] t = var.GetType().GetGenericArguments();
Type typeToGenerate = typeof(Dictionary<,>);
Type[] tParameters = new Type[] { typeof(Guid), t[0] };
Type newType = typeToGenerate.MakeGenericType(tParameters);
object obj = Activator.CreateInstance(newType);
}
else
{
throw new InvalidCastException("Wrong type");
}
// do something with the new Dictionary...
}
|