Generic Method Reflection : Generic Method « Generic « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Reflection;

    class GenericMethodReflection
    {
        public static void PrintTypeParameter<T>()
        {
            Console.WriteLine (typeof(T));
        }

        static void Main()
        {
            Type type = typeof(GenericMethodReflection);
            MethodInfo definition = type.GetMethod("PrintTypeParameter");        
            MethodInfo constructed;
            constructed = definition.MakeGenericMethod(typeof(string));       
            constructed.Invoke(null, null);
        }
    }








18.12.Generic Method
18.12.1.A generic method
18.12.2.constrained method calls
18.12.3.A generic method: constrol the parameter
18.12.4.Generic and non Generic compare
18.12.5.Generic Method Demo
18.12.6.Generic Method Reflection
18.12.7.Multiple Argument Inference with value and object