Replies: 1 comment 3 replies
-
@AnakinSklavenwalker It's the base type of the generic type argument. Try this: class C<T> { }
class D<T> where T : struct { }
static void test()
{
//b1: System.Object means ... no constraint for T
var b1 = typeof(C<>).GetGenericTypeDefinition().GetGenericArguments()[0].BaseType;
//b2: System.ValueType means ... constraint T must struct
var b2 = typeof(D<>).GetGenericTypeDefinition().GetGenericArguments()[0].BaseType;
//ok, can make a generic type from template ... of for example C<string>
var t1 = typeof(C<>).GetGenericTypeDefinition().MakeGenericType(typeof(string));
// create instance ... new C<string>();
var t2 = Activator.CreateInstance(t1);
// cast object t2 to C<string> t3
var t3 = t2 as C<string>;
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
According to ECMA I.8.7 p. 37 generic parameter types don't have a base type.
However the following code indicates that they have one, at least at runtime.
I'm sure both, the spec and the reflection implementation are correct, but i don't really understand what's happening here. Hope someone can help me.
Cheers
Beta Was this translation helpful? Give feedback.
All reactions