CodeConditionStatement 类

定义

表示条件分支语句,通常表示为一个 if 语句。

public ref class CodeConditionStatement : System::CodeDom::CodeStatement
public class CodeConditionStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeConditionStatement : System.CodeDom.CodeStatement
type CodeConditionStatement = class
    inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeConditionStatement = class
    inherit CodeStatement
Public Class CodeConditionStatement
Inherits CodeStatement
继承
CodeConditionStatement
属性

示例

此示例演示如何使用 来 CodeConditionStatement 表示 if 具有 块的 else 语句。

// Create a CodeConditionStatement that tests a boolean value named boolean.
array<CodeStatement^>^temp0 = {gcnew CodeCommentStatement( "If condition is true, execute these statements." )};
array<CodeStatement^>^temp1 = {gcnew CodeCommentStatement( "Else block. If condition is false, execute these statements." )};

// The statements to execute if the condition evalues to false.
CodeConditionStatement^ conditionalStatement = gcnew CodeConditionStatement( gcnew CodeVariableReferenceExpression( "boolean" ),temp0,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.
// }
// 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.
    // }
' 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.

注解

CodeConditionStatement 可用于表示由条件表达式组成的代码、条件表达式计算结果为 true时要执行的语句集合,以及条件表达式计算结果为 false时要执行的语句的可选集合。 以 CodeConditionStatement 多种语言作为 if 语句生成 。

属性 Condition 指示要测试的表达式。 属性 TrueStatements 包含要测试的表达式的计算结果为 true时要执行的语句。 属性 FalseStatements 包含要测试的表达式的计算结果为 false时要执行的语句。

构造函数

CodeConditionStatement()

初始化 CodeConditionStatement 类的新实例。

CodeConditionStatement(CodeExpression, CodeStatement[])

使用指定的条件和语句初始化 CodeConditionStatement 类的新实例。

CodeConditionStatement(CodeExpression, CodeStatement[], CodeStatement[])

使用指定的条件和语句初始化 CodeConditionStatement 类的新实例。

属性

Condition

获取或设置要计算 truefalse 的表达式。

EndDirectives

获取包含结束指令的 CodeDirectiveCollection 对象。

(继承自 CodeStatement)
FalseStatements

获取在条件表达式计算为 false 时执行的语句集合。

LinePragma

获取或设置代码语句所在的行。

(继承自 CodeStatement)
StartDirectives

获取包含开始指令的 CodeDirectiveCollection 对象。

(继承自 CodeStatement)
TrueStatements

获取在条件表达式计算为 true 时执行的语句集合。

UserData

获取当前对象的用户可定义数据。

(继承自 CodeObject)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于