4

我是使用反射的新手,经过三天的搜索,我无法得到结果。我会很感激一些帮助。

我想要做的是将结果绑定到一个列表。

我有一堂课:

public class DropdownList
{
    public string ID { get; set; }
    public string Description { get; set; }
}

我有一个功能:

public static List<DropdownList> getDropdownList(string Method)
{
    using (var Context = new WebDataContext())
    {
        var method = Context.GetType().GetMethod(Method);
        if (method == null) throw new InvalidOperationException("Defined DataContext does not have method" + Method);

        var result = method.Invoke(Context,null);

        var toReturn = (from x in result select new DropdownList { ID = x.???, Description = x.??? }).ToList();

        return toReturn;
    } 
}

我将它绑定到一个组合框:

StatuscomboBoxProperties.DataSource = getDropdownList("Get_SupplierList");

toReturn 中的“结果”给出以下错误:

could not find an implementation of the query pattern for source type "system.Reflection.MethodInfo' "Select" not found

我的问题是:如果您将鼠标悬停在结果上,则有一个结果视图,我可以看到从该方法返回的数据,但是我将如何将我的列表绑定到该数据。

4

1 回答 1

0

我改变了方法,我的应用程序运行良好。对我的新方法的任何评论或建议将不胜感激。

我继续上课:

public class DropdownList
{
    public int ID { get; set; }
    public string Description { get; set; }
}

我将我的功能更改为:

public static List<DropdownList> getDropdownList(string Method)
{
    using (var Context = new WebDataContext())
    {
        var toReturn = Context.ExecuteQuery<DropdownList>("EXEC " + Method).ToList();
        return toReturn;
    } 
}

我将它绑定到一个组合框:

StatuscomboBoxProperties.DataSource = getDropdownList("Get_SupplierList");

“Get_SupplierList”由组合框传入。

于 2013-10-15T14:16:37.650 回答