Type.IsGenericTypeDefinition : Type « System « C# / C Sharp by API






Type.IsGenericTypeDefinition

   

using System;
using System.Reflection;

public class MyClass<T, V> {
    public T membera;
}

public class XClass {
    public void MethodA<T>() {
    }
}

class Starter {

    static void Main() {
        Type[] types = { typeof(MyClass<,>), typeof(MyClass<int, int>) };
        bool[,] bresp = { {types[0].IsGenericType,
                               types[0].IsGenericTypeDefinition},
                              {types[1].IsGenericType,
                               types[1].IsGenericTypeDefinition}};
        Console.WriteLine("Is MyClass<,> a generic type? " + bresp[0, 0]);
        Console.WriteLine("Is MyClass<,> open? " + bresp[0, 1]);
        Console.WriteLine("Is MyClass<int,int> a generic type? " + bresp[1, 0]);
        Console.WriteLine("Is MyClass<int,int> open? " + bresp[1, 1]);

        Type tObj = typeof(XClass);
        MethodInfo method = tObj.GetMethod("MethodA");
        bool[] bMethod ={method.IsGenericMethod, method.IsGenericMethodDefinition};
        Console.WriteLine("Is XClass.MethodA<T> a generic method? " + bMethod[0]);
        Console.WriteLine("Is XClass.MethodA<T> open? " + bMethod[1]);
    }
}

   
    
    
  








Related examples in the same category

1.Type.BaseType
2.Type.ContainsGenericParameters
3.Type.FullName
4.Type.GetConstructor
5.Type.GetCustomAttributes
6.Type.GetEvents()
7.Type.GetFields()
8.Type.GetGenericArguments()
9.Type.GetGenericTypeDefinition()
10.Type.GetInterfaces()
11.Type.GetMethod(String methodName);
12.Type.GetMethods()
13.Type.GetProperties()
14.Type.GetType(String typeName)
15.Type.GetType(String typeName, true)
16.Type.GetType(String typeName, true, true);
17.Type.IsAbstract
18.Type.IsClass
19.Type.IsCOMObject
20.Type.IsEnum
21.Type.IsSealed
22.Type.MakeGenericType
23.Type.Name
24.Type.ReflectionOnlyGetType
25.Type.UnderlyingSystemType