0
public static List<someclass> OrderAsc(
    List<someclass> object, 
    specific_field_by_someone )
{
    return object.OrderBy(...get field to be sorted...);
}

I just want to make data structure like this

Dictionary<string, ???> data_table = new Dictionary<string, ????>() {
    {"id", x => x.id },
    {"name", x => x.name }
}

that can be used with

object.OrderBy(data_table["name"])...
Noctis
  • 11,507
  • 3
  • 43
  • 82
SuperMENG
  • 439
  • 4
  • 7
  • 15
  • 1
    I'm really confused here you want to order a dictionary? you want to order a list? do you want a list to dictionary? – dbarnes Nov 08 '13 at 05:22
  • what does ??? and ???? represent? – Miller Nov 08 '13 at 05:22
  • 1
    This should be what you need: http://stackoverflow.com/questions/41244/dynamic-linq-orderby-on-ienumerablet – LUKE Nov 08 '13 at 05:25
  • I'm sorry to make you guys confuse.. I just want to know how to make delegate to method OrderBy and OrderByDescending.. – SuperMENG Nov 08 '13 at 05:31

1 Answers1

0

try use Func like this

public static List<someclass> OrderAsc(
    List<someclass> object, 
    specific_field_by_someone )
{
    var data_table = new Dictionary<string, Func<someclass,object>>() 
    {
        {"id", x => x.id },
        {"name", x => x.name }
    }

    return object.OrderBy(data_dable["name"]);
}
Grundy
  • 13,356
  • 3
  • 35
  • 55