Can ternary conditional expressions be represented in the CodeDOM?

G

Guest

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

Guest

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

Damien

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top