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 представления 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 |
Получает или задает выражение для вычисления |
| EndDirectives |
Получает объект CodeDirectiveCollection, содержащий конечные директивы. (Унаследовано от CodeStatement) |
| FalseStatements |
Получает коллекцию операторов для выполнения, если условное выражение вычислено как |
| LinePragma |
Получает или задает строку, в которой содержится оператор кода. (Унаследовано от CodeStatement) |
| StartDirectives |
Получает объект CodeDirectiveCollection, содержащий начальные директивы. (Унаследовано от CodeStatement) |
| TrueStatements |
Получает коллекцию операторов для выполнения, если условное выражение вычислено как |
| UserData |
Получает определяемые пользователем данные для текущего объекта. (Унаследовано от CodeObject) |
Методы
| Equals(Object) |
Определяет, равен ли указанный объект текущему объекту. (Унаследовано от Object) |
| GetHashCode() |
Служит хэш-функцией по умолчанию. (Унаследовано от Object) |
| GetType() |
Возвращает объект Type для текущего экземпляра. (Унаследовано от Object) |
| MemberwiseClone() |
Создает неполную копию текущего объекта Object. (Унаследовано от Object) |
| ToString() |
Возвращает строку, представляющую текущий объект. (Унаследовано от Object) |