This is what im thinking...

Aug 24, 2007 at 2:00 PM
Hi, i would like to explain how im going to try using Flee, so you can tell me if such thing is not possible...

I have bussines objects, for example purpouses lets use Client, and Client as some properties like Name, BirthDate, Invoices (to put some set of values) and CreditLimit

Now i create a custom attribute, lets call it BizExpression with a propertie Name and other propertie FleeExpression

Lets code it. (more or less, just the important things)

BizExpression(Name = "Client")
public class Client

BizExpression(Name = "Name", FleeExpression = "Client.Name")
public String Name;

BizExpression(Name = "Credit Limit", FleeExpression = "Client.CreditLimit")
public float CreditLimit;


Ready with this, now lets go to other application, lets say an Expression Builder

Supouse i load the Assembly of bussines object and loop thru types with the BizExpression attribute using BizExpression's Name i build a tree node to add a treeview, so i load a tree of my bussines objects, each node has also his FleeExpression.

Now in a entry near the tree i build some expression:

If(Client.CreditLimit > 999, "Call for Promotion", "Low limit")

Client.CreditLimit was obtained by a double click on the node "Credit Limit" children of node "Client" or by drag and drop.

Ok, i store the expression in a database with a name like "Credit Situation" for later use.

Now in "later use" :) im doing some report and in some place for the client im procesing i would like to evaluate his "Client Situation"...

I should do:

ExpressionOptions options = new ExpressionOptions();
options.Imports.AddType(typeof(MyBizNamespace.Client)); // can i add the whole namespace ?

//more real solution is loop thru the classes of the assembly that have BizExpression attribute
//and add each one of this to imports...

foreach (Client c in MyClients)
Expression e = new Expression("If(Client.CreditLimit > 999, "Call for Promotion", "Low limit")", c, options);
ExpressionEvaluator<String> evaluator = (ExpressionEvaluator<String>)e.Evaluator;
String ClientSituation = evaluator();

Ok, this is from a bird view the idea, the key here is that the Expression builder application is used by end users not for me, and the reports are end users made also.

What you people think about this ?

Aug 24, 2007 at 9:55 PM
If I understand correctly, you have some business objects and you'd like to evaluate expressions which make use of properties on those objects. Correct?

In that case, you could do the following:
DynamicExpressionOwner owner = new DynamicExpressionOwner();
// Define a variable named "Client" of type Client
owner.DefineVariable("Client", typeof(Client));
foreach(Client c in MyClients)
  // Set the variable value to the current client instance
  owner.SetVariableValue("Client", c);
  // We can now access all properties of the instance in the expression
  Expression e = new Expression("Client.CreditLimit + 1", owner); 
 // Evaluate as usual

What this does is define a variable as "Client" of the type Client. Once defined, you can use the name "Client" in an expression and the "." operator to access any public properties.
Aug 25, 2007 at 12:37 PM
Thanks Eugene, its really more complex im just starting.

In simple terms users make word documents with bookmarks, from client name to debt and taxes special calculations etc, i read the word from .NET and get all bookmars. Show to the user the tree of bussiness objects and the bookmarks for the user tell wich object goes to wich bookmark.

There are things (calculations) that are not a part of my bussines object directly, here is where flee comes, so the user can define his own business expresions (using bussiness objects) and then assign this expression to bookmarks, this is essential.

This need to be reusable because similar situation happens with other component than word generation.