CodeDom VB code generation

  • Thread starter Thread starter Tim Bond
  • Start date Start date
T

Tim Bond

I am using the Codedom classes to generate some code. Generally it is
pretty intuitive but I have not been able to determine how to generate the
'not' statement. Specifically I want to be able to generate something like:

if not testexpression then
...
end if

The if is fine it is a codeConditionStatement but I am not sure how to do
the 'not'.

Tim
 
Tim Bond said:
I am using the Codedom classes to generate some code. Generally it
is pretty intuitive but I have not been able to determine how to
generate the 'not' statement. Specifically I want to be able to
generate something like:

if not testexpression then
...
end if

The if is fine it is a codeConditionStatement but I am not sure how
to do the 'not'.

I've never used CodeDom so far, so there's a high probability that I am
wrong, but maybe it is

New CodeBinaryOperatorExpression( _
TestExpression, _
CodeBinaryOperatorType.ValueEquality, _
New CodePrimitiveExpression(False), _
)

? Does this work?
 
Hi Tim,

If Armin's BinaryOperator using Equality doesn't do the trick, I'm
thinking you'll have to use a CodeSnippetExpression and supply the "Not" that
way.

Regards,
Fergus
 
It doesn't actually generate a 'NOT' but it has the same effect - Thanks for
the suggestion

Tim
 
I thought of this but I wasn't sure how to combine the snippet and the
condition into a single condition. It is logically one statement operating
on another like a function call with a parameter but ther isn't a way to
expand codeDom expressions as part of the snippet.

Fortunately Armin's suggestion - whilst it doesn't generate a not - is
functionally equivalent - near enough.

Thanks Tim
 
Hi Tim,

This should do the trick. If you know that it won't require brackets,
simpler still

Dim oNotExpr As New CodeSnippetExpression ("Not (" & oExpr.ToString & ")")

Regards,
Fergus
 
Back
Top