Export (0) Print
Expand All

CodeConditionStatement Class

Represents a conditional branch statement, typically represented as an if statement.

For a list of all members of this type, see CodeConditionStatement Members.

System.Object
   System.CodeDom.CodeObject
      System.CodeDom.CodeStatement
         System.CodeDom.CodeConditionStatement

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeConditionStatement
   Inherits CodeStatement
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeConditionStatement : CodeStatement
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeConditionStatement : public CodeStatement
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeConditionStatement extends CodeStatement

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

CodeConditionStatement can be used to represent code that consists of a conditional expression, a collection of statements to execute if the conditional expression evaluates to true, and an optional collection of statements to execute if the conditional expression evaluates to false. A CodeConditionStatement is generated in many languages as an if statement.

The Condition property indicates the expression to test. The TrueStatements property contains the statements to execute if the expression to test evaluates to true. The FalseStatements property contains the statements to execute if the expression to test evaluates to false.

Example

[Visual Basic, C#, C++] This example demonstrates using a CodeConditionStatement to represent an if statement with an else block.

[Visual Basic] 
' Create a CodeConditionStatement that tests a boolean value named boolean.
 Dim conditionalStatement As New CodeConditionStatement( _
      New CodeVariableReferenceExpression("boolean"), _
      New CodeStatement() {New CodeCommentStatement("If condition is true, execute these statements.")}, _
      New CodeStatement() {New CodeCommentStatement("Else block. If condition is false, execute these statements.")})

' A Visual Basic code generator produces the following source code for the preceeding example code:

' If [boolean] Then
'     'If condition is true, execute these statements.
' Else
'     'Else block. If condition is false, execute these statements.


[C#] 
// Create a CodeConditionStatement that tests a boolean value named boolean.
CodeConditionStatement conditionalStatement = new CodeConditionStatement(
    // The condition to test.
    new CodeVariableReferenceExpression("boolean"),
    // The statements to execute if the condition evaluates to true.
    new CodeStatement[] { new CodeCommentStatement("If condition is true, execute these statements.") },
    // The statements to execute if the condition evalues to false.
    new CodeStatement[] { new CodeCommentStatement("Else block. If condition is false, execute these statements.") } );

// A C# code generator produces the following source code for the preceeding example code:

// if (boolean) 
// {
    //     // If condition is true, execute these statements.
// }
// else {
//     // Else block. If condition is false, execute these statements.
    // }        
    

[C++] 
// Create a CodeConditionStatement that tests a boolean value named boolean.

CodeStatement* temp0 [] = {new CodeCommentStatement(S"If condition is true, execute these statements.")};
CodeStatement* temp1 [] = {new CodeCommentStatement(S"Else block. If condition is false, execute these statements.")};

CodeConditionStatement* conditionalStatement = new CodeConditionStatement(
    // The condition to test.
    new CodeVariableReferenceExpression(S"boolean"),
    // The statements to execute if the condition evaluates to true.
    temp0,
    // The statements to execute if the condition evalues to false.
    temp1 );

// A C# code generator produces the following source code for the preceeding example code:

// if (boolean) 
// {
//     // If condition is true, execute these statements.
// }
// else {
//     // Else block. If condition is false, execute these statements.
// }        

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.CodeDom

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeConditionStatement Members | System.CodeDom Namespace

Show:
© 2014 Microsoft