CodeConditionStatement 类
定义
表示条件分支语句,通常表示为一个 if
语句。Represents a conditional branch statement, typically represented as an if
statement.
public ref class CodeConditionStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeConditionStatement : System.CodeDom.CodeStatement
type CodeConditionStatement = class
inherit CodeStatement
Public Class CodeConditionStatement
Inherits CodeStatement
- 继承
- 属性
示例
此示例演示CodeConditionStatement如何使用来if
表示语句和else
块。This example demonstrates using a CodeConditionStatement to represent an if
statement with an else
block.
// 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 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
. 在许多语言中if
以语句的形式生成。 CodeConditionStatementA CodeConditionStatement is generated in many languages as an if
statement.
Condition属性指示要测试的表达式。The Condition property indicates the expression to test. 如果TrueStatements要测试的表达式的计算结果为true
, 则属性包含要执行的语句。The TrueStatements property contains the statements to execute if the expression to test evaluates to true
. 如果FalseStatements要测试的表达式的计算结果为false
, 则属性包含要执行的语句。The FalseStatements property contains the statements to execute if the expression to test evaluates to false
.
构造函数
CodeConditionStatement() |
初始化 CodeConditionStatement 类的新实例。Initializes a new instance of the CodeConditionStatement class. |
CodeConditionStatement(CodeExpression, CodeStatement[]) |
使用指定的条件和语句初始化 CodeConditionStatement 类的新实例。Initializes a new instance of the CodeConditionStatement class using the specified condition and statements. |
CodeConditionStatement(CodeExpression, CodeStatement[], CodeStatement[]) |
使用指定的条件和语句初始化 CodeConditionStatement 类的新实例。Initializes a new instance of the CodeConditionStatement class using the specified condition and statements. |
属性
Condition |
获取或设置要计算 |
EndDirectives |
获取包含结束指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains end directives. (继承自 CodeStatement) |
FalseStatements |
获取在条件表达式计算为 |
LinePragma |
获取或设置代码语句所在的行。Gets or sets the line on which the code statement occurs. (继承自 CodeStatement) |
StartDirectives |
获取包含开始指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains start directives. (继承自 CodeStatement) |
TrueStatements |
获取在条件表达式计算为 |
UserData |
获取当前对象的用户可定义数据。Gets the user-definable data for the current object. (继承自 CodeObject) |
方法
Equals(Object) |
确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
GetHashCode() |
用作默认哈希函数。Serves as the default hash function. (继承自 Object) |
GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
ToString() |
返回一个表示当前对象的 string。Returns a string that represents the current object. (继承自 Object) |