2

Is it possible to order an expandable collection of expando objects.

I found this about how to sort an ObservableCollection. However, I need to know the name of the property in the lambda expression. I don't know this because the properties of the expando objects are dynamic.

Community
  • 1
  • 1
Carlos Blanco
  • 8,592
  • 17
  • 71
  • 101

1 Answers1

0

Ultimately your ExpandoObject needs to implement IComparable<T> or IComparable to use the technique in the link you reference (assuming you mean the article mentioned in the accepted answer).

If you're referring to this version of ExpandoObject, it does not implement either interface. So, the straightforward answer is to implement one of those two interfaces.

Fundamentally you need to have some knowledge of how to compare two different instances of ExpandoObject to know which to sort before the other.

If your ExpandoObjects are completely dynamic (as opposed to say having certain common properties that are extended dynamically), how logically do you intend to compare two instances for sorting? If you can provide more detail around your question, I can provide a more specific answer.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • My expando objects are totally dynamic. We use them to represent data retrieved from the DB. I just want to order the objects Ascending or Descending based on whatever column(s) the user wants. One column in the DB is one property of the expando objects – Carlos Blanco Oct 04 '11 at 13:59
  • In that case, you can implement IComparable. You can get dynamic property values based on the (string) name of those values e.g. as specified by the user. See http://stackoverflow.com/questions/4939508/get-value-of-c-dynamic-property-via-string – Eric J. Oct 04 '11 at 18:39