CodeDom VB code generation

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
 
A

Armin Zingler

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?
 
F

Fergus Cooney

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
 
T

Tim Bond

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

Tim
 
T

Tim Bond

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
 
F

Fergus Cooney

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
 

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

Similar Threads


Top