Home All Groups Group Topic Archive Search About

CodeDom conditional expression.

Author
7 Jan 2007 9:15 AM
Kevin Burton
I would like to know the sequence of calls required to create a conditional
expression like:

if(a != null)
{
}

So far I have only come up with

if(a)
{
}

Which will work but I would like to know how to form expressions with '!=',
'==', '>', etc.

Thank you for your help.

Kevin Burton

Author
8 Jan 2007 10:01 AM
Damien
Kevin Burton wrote:

Show quote
> I would like to know the sequence of calls required to create a conditional
> expression like:
>
> if(a != null)
> {
> }
>
> So far I have only come up with
>
> if(a)
> {
> }
>
> Which will work but I would like to know how to form expressions with '!=',
> '==', '>', etc.
>
> Thank you for your help.
>
> Kevin Burton

Hi Kevin,

It would have helped if you'd posted the code you had already, so we
could work and adapt from that. Here's some code from one of my
projects, in VB, but should be amenable to use in C# if that's your
poison:

            ifActualChange.Condition = New
CodeBinaryOperatorExpression(col.mVarRef,
CodeBinaryOperatorType.IdentityInequality, __Nothing)

where col.mVarRef is a property that returns a
CodeVariableReferenceExpression, and __Nothing is a global variable set
to a CodePrimitiveExpression of Nothing (you'd use a
CodePrimitiveExpression of null in C#).

You should find that CodeBinaryOperatorExpression meets most of your
needs, although I've found it to be curiosly limitied in some places in
the past.

Damien

AddThis Social Bookmark Button