c# - How can I access a property dynamically by name without using reflection? -


at first using:

sortedlist = unsorted.asparallel().orderby(myitem => typedescriptor.getproperties(myitem)[firstsort.item2].getvalue(myitem)); 

where firstsort.item2 string name of property. however, performance degraded number of items in unsorted list increased. (as expected)

is there way without using reflection?

the brute force approach like:

if(firstsort.item2 == "size")    sortedlist = unsorted.asparallel().orderby(myitem => myitem.size); else if(firstsort.item2 == "price")    sortedlist = unsorted.asparallel().orderby(myitem => myitem.price); ... 

i'm looking accomplish above behavior, without having hardcode in different properties in interface.

you can use expression<t> pre-compile expressions you're passing orderby. can them @ runtime.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -