using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;namespace WindowsApplication275
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); MethodInfo get = null; foreach (MethodInfo MI in this.GetType().GetMethods())
if (MI.Name == "Get" && MI.IsGenericMethod)
get = MI; get = get.MakeGenericMethod(new Type[] { typeof(TItem) });
get.Invoke(this,new Object[]{"XXX"});
} public class TTypeToGet
{
} public class TItem : TTypeToGet
{
} public TTypeToGet Get<TTypeToGet>(string id) where TTypeToGet : TItem
{
return (TTypeToGet)Get(id);
} public TItem Get(string id)
{
MessageBox.Show(id); return new TItem();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;namespace WindowsApplication275
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); MethodInfo get = null; foreach (MethodInfo MI in this.GetType().GetMethods())
if (MI.Name == "Get" && MI.IsGenericMethod)
get = MI; get = get.MakeGenericMethod(new Type[] { typeof(TItem) });
get.Invoke(this,new Object[]{"XXX"});
} public class TTypeToGet
{
} public class TItem : TTypeToGet
{
} public TTypeToGet Get<TTypeToGet>(string id) where TTypeToGet : TItem
{
return (TTypeToGet)Get(id);
} public TItem Get(string id)
{
MessageBox.Show(id); return new TItem();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货