【发布时间】:2014-06-04 09:47:58
【问题描述】:
在这段代码中,MyEvents 出现了一个错误。那里发生了什么。以及如何通过 MyEvents 函数实现传递 TType 值
public class MListBox : ListBox
{
public Type TType { get; set; }
public void LoadList()
{
MyEvents<TType , TType >.LoadList("getList").ForEach(w => this.Items.Add(w));
}
}
public void main(string[] args)
{
MListBox mb= new MListBox();
mb.TType = typeof(STOCK);
mb.LoadList();
}
public static class MyEvents<T,M> where T : class where M : class
{
public static M m;
public static T t;
public static List<objectCollection> LoadList(string _method)
{
m = Activator.CreateInstance<M>();
MethodInfo method = typeof(M).GetMethod(_method);
List<objectCollection> ret = (List<objectCollection>)method.Invoke(m, null);
return ret;
}
}
public class STOCK()
{
}
谢谢,
【问题讨论】:
-
给出错误总是有帮助的。
-
谢谢你,但是我如何在我的自定义列表框中传递 t-class
-
T不是变量。 -
我在代码中没有看到任何错误,你可以像这样使用它
MListBox<YourClass> a = new MListBox<YourClass>();所以模板变量 T 在这种情况下将是 YourClass