zone

zone

  • NA
  • 1
  • 0

Dynamic building of object formula expressions

Jan 13 2009 12:02 PM
Hi there,

My users have requested I provide a way for them to enter formulas to work on the data they work with (stock prices). For example, they want to be able to enter a formula along the lines of   ((Price < 50.00) OR (Price < TodaysLow)) AND (TodaysVolume > 50000), and if that evaluates to true then perform some action.

I am not sure how best to go about this? I was thinking maybe looking at Linq Expression Trees but I can't figure out how to design code so that comparison values can be either actual values or the contents of fields / properties / methods on other objects, nor of how to deal with nested ANDs / ORs, and brackets.

Ideally I would like to avoid hard coding large switch statements so that if I add another property to an object down the line it will automatically be available to the formula builder (I assume some sort of reflection will be needed for this).

Anybody ever done anything like this, or where I might be able to look online to learn how to do this?

Cheers!


Answers (2)