C # Result of binding Linq2Sql reflection to list

I am new to Reflection, and after three days of searching, I could not get the result. I would appreciate help.

What I'm trying to do is bind the result to a list.

I have a class:

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

I have a function:

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;
    } 
}

I associate this with a list:

StatuscomboBoxProperties.DataSource = getDropdownList("Get_SupplierList");

The result of the "toReturn" result is the following error:

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

My question is: if you hover over the result, a Result View will appear, and I can see the data returned from the method, but how will I link my list to this data.

+4
source share
1 answer

, . .

:

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" combobox.

0

All Articles