Tracking Expressions

Sep 9, 2009 at 2:21 PM

I have another question wrt to the implementation though.

  1. Is it possible to track Distincts on a particular property within observablecollection<T>. Say I need to bind distincts of Person.Name within the the collection and bind to a dropdownlist.
  2. Is it possible to track Expressions based out of a calculation on properties. E.g. Savings = (Person.Income * 30%) - Person.Expense and bind it to a control or a column in a datagrid.

I am sure this is what you intended with this api, but a guidance in the implementation approach will be very helpful.

Thanks for your help

Vinay

Coordinator
Sep 9, 2009 at 3:10 PM

Hi Vinay,

Yes, both are very possible:

For the first you can use the standard Enumerable.Distinct method like:

ExpressionObserver.Execute(
    Persons,
    persons => persons.Select( p => p.Name ).Distinct()
).Cascade();

The Cascade method will return an IEnumerable<string> provided Name is of type string.

For the second just use the expression you want:

ExpressionObserver.Execute(
    Person,
    person => person.Income * 0.3 - person.Expense
);

And bind to the Value property of the returned IValueProvider. Income and Expense properties naturaly need to be observable if you want the resulting Value to react to changes. (The owning class needs to implement INotifyPropertyChanged (Silverlight))

If you have a collection of persons:

ExpressionObserver.Execute(
    Persons,
    persons => 
        from p in persons
        select p.Income * 0.3 - p.Expense
).Cascade();

If you feel like donating an Obtics users guide, I would be very interested. :-)

Regs,

Thomas

 

 

 

Sep 10, 2009 at 5:49 PM

Thomas,

Thanks for the quick response. I would love to be helpful whereever I could.

Vinay