Cause: Customizing a GridView control whose data source comes from a common method get<t> (), according to your incoming T to the database to get the corresponding data, the problem is to define the GridView control can not be set on the interface side of the use of generics, Data can only be bound at each time that the GridView control is used. It doesn't matter if you don't understand the cause, we use a piece of code to describe the problem:
I would like to use the type TT from the outside to invoke the Test1 paradigm method.
Class Program
{
static void Main (string[] args)
{
MyClass m = new MyClass ();
M.tt = typeof (program);
M.test2 ();
}
}
Class MyClass
{
Public Type TT {get; set;}
public int UserID {get; set;}
public string Name {get; set;}
public string Test2 ()
{
Test1 <T> ();
I would like to use the type TT from the outside to invoke the Test1 paradigm method.
}
public string Test1 <T> ()
{
Return typeof (T). ToString ();
}
}
Solution:
Class MyClass
{
Public Type TT {get; set;}
public int UserID {get; set;}
public string Name {get; set;}
public string Test2 ()
{
Object result = typeof (MyClass). GetMethod ("Test1").
MakeGenericMethod (TT). Invoke (this, null);
return result. ToString ();
}
public string test1<t> ()
{
Return typeof (T). ToString ();
}
}Content sharing from: http://www.cnblogs.com/nuaalfm/archive/2009/02/24/1397340.html Thank you.
Solution to invoke the Paradigm method with the type passed in