... I know I could use a CodeSnippetExpression to do it, but that would
somewhat hardcode the resulting tree. I was looking for something like:
CodeTernaryExpression(
CodeExpression test,
CodeExpression trueExpression,
CodeExpression falseExpression);
Which would, of course, get turned into the corresponding:
(test ? trueExpression : falseExpression)
expression in C#, C++, or even J# (I believe). I guess it's only VB.NET
that doesn't have a ternary expression but I don't know for sure.
I know, I know, for generated code there's no real reason to use a ternary
expression, but coding habits are hard to break, even when writing meta-code
:-)
Regards,
-- TB
AMercer - 10 Jul 2007 13:56 GMT
> I guess it's only VB.NET
> that doesn't have a ternary expression but I don't know for sure.
VB does have such an expression, it is IIF. Be advised that the semantics
are different - both the true and false expressions are evaluated regardless
of the value of the test expression.
Damien - 10 Jul 2007 14:32 GMT
On Jul 10, 1:08 am, Thomas W. Brown
<thomas_w_br...@countrywide.NOSPAM.com> wrote:
> ... I know I could use a CodeSnippetExpression to do it, but that would
> somewhat hardcode the resulting tree. I was looking for something like:
[quoted text clipped - 17 lines]
> Regards,
> -- TB
There are more surprising ommissions from the CodeDom than ternary
expressions - things you would expect to find in ANY language (and as
AMercer pointed out, VB does have IIF).
For instance, try looking for:
Unary Minus
Xor
Value Inequality
Or try generating a while loop. Or a lock expression (Synclock in VB).
Or a Negative test (If Not xxxxx in VB/if(!xxxxx) in C#)
Damien