... 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

RE: Can ternary conditional expressions be represented in the CodeDOM? by AMercer

AMercer
Tue Jul 10 07:56:02 CDT 2007

> 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.

Re: Can ternary conditional expressions be represented in the CodeDOM? by Damien

Damien
Tue Jul 10 08:32:16 CDT 2007

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:
>
> 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

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