CodeConditionStatement Klass

Definition

Representerar en villkorsstyrd gren-instruktion, vanligtvis representerad som en if instruktion.

public ref 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
[<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
Arv
CodeConditionStatement
Attribut

Exempel

Det här exemplet visar hur du använder en CodeConditionStatement för att representera en if -instruktion med ett else block.

// 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.

Kommentarer

CodeConditionStatement kan användas för att representera kod som består av ett villkorsuttryck, en samling instruktioner som ska köras om villkorsuttrycket utvärderas till trueoch en valfri samling instruktioner som ska köras om villkorsuttrycket utvärderas till false. A CodeConditionStatement genereras på många språk som en if instruktion.

Egenskapen Condition anger uttrycket som ska testas. Egenskapen TrueStatements innehåller de instruktioner som ska köras om uttrycket som ska testas utvärderas till true. Egenskapen FalseStatements innehåller de instruktioner som ska köras om uttrycket som ska testas utvärderas till false.

Konstruktorer

Name Description
CodeConditionStatement()

Initierar en ny instans av CodeConditionStatement klassen.

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

Initierar en ny instans av CodeConditionStatement klassen med angivet villkor och instruktioner.

CodeConditionStatement(CodeExpression, CodeStatement[])

Initierar en ny instans av CodeConditionStatement klassen med angivet villkor och instruktioner.

Egenskaper

Name Description
Condition

Hämtar eller ställer in uttrycket för att utvärdera true eller false.

EndDirectives

Hämtar ett CodeDirectiveCollection objekt som innehåller slutdirektiv.

(Ärvd från CodeStatement)
FalseStatements

Hämtar samlingen med instruktioner som ska köras om villkorsuttrycket utvärderas till false.

LinePragma

Hämtar eller anger den rad där kodsatsen inträffar.

(Ärvd från CodeStatement)
StartDirectives

Hämtar ett CodeDirectiveCollection objekt som innehåller startdirektiv.

(Ärvd från CodeStatement)
TrueStatements

Hämtar samlingen med instruktioner som ska köras om villkorsuttrycket utvärderas till true.

UserData

Hämtar användardefinierbara data för det aktuella objektet.

(Ärvd från CodeObject)

Metoder

Name Description
Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Gäller för