Macros?

  • Thread starter Thread starter rd
  • Start date Start date
R

rd

Is the following possible in C#? (dynamic compilation?)

Let's say we have a statement stored in a table string field
called "critera1" and it equals "x > 10" (or any other logic)

At runtime the code reads the string and uses it in the code

IF criteria1 THEN ...
ELSE ...

Rich
 
Dynamic compilation is possible.  As is storing expressions as data (see  
the Expression class).  The latter is somewhat more convenient, but would  
only be appropriate if you can predict the expressions ahead of time.

That said, if your expressions are relatively simple, it might make more  
sense to parse them yourself and build an Expression from scratch.  As far  
as I know, there's no "auto-compile" functionality for the Expression  
class, other than compiling lambdas in code (which requires you know the  
expression at compile time).

While that is true, there is an "official" (that is, coming from MS)
C# sample which is essentially a parser that generates Expression<T>
objects. It is included in the sample pack that can be downloaded from
this link:

http://msdn.microsoft.com/en-us/vcsharp/bb894665.aspx

Of course, that being sample code, it's not guaranteed to be bug-free
etc. But some people that I know have found it useful, and used it in
commercial projects.
 
Back
Top