Freigeben über


CodeLabeledStatement Klasse

Definition

Stellt eine beschriftete Anweisung oder eine eigenständige Bezeichnung dar.

public ref class CodeLabeledStatement : System::CodeDom::CodeStatement
public class CodeLabeledStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeLabeledStatement : System.CodeDom.CodeStatement
type CodeLabeledStatement = class
    inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeLabeledStatement = class
    inherit CodeStatement
Public Class CodeLabeledStatement
Inherits CodeStatement
Vererbung
CodeLabeledStatement
Attribute

Beispiele

Im folgenden Beispielcode wird die Verwendung eines CodeGotoStatement Und eines CodeLabeledStatement zum Umleiten des Programmflusses veranschaulicht.

// Declares a type to contain the example code.
CodeTypeDeclaration type1 = new CodeTypeDeclaration("Type1");
// Declares an entry point method.
CodeEntryPointMethod entry1 = new CodeEntryPointMethod();
type1.Members.Add( entry1 );
// Adds a goto statement to continue program flow at the "JumpToLabel" label.
CodeGotoStatement goto1 = new CodeGotoStatement("JumpToLabel");
entry1.Statements.Add( goto1 );
// Invokes Console.WriteLine to print "Test Output", which is skipped by the goto statement.
CodeMethodInvokeExpression method1 = new CodeMethodInvokeExpression(
    new CodeTypeReferenceExpression("System.Console"), "WriteLine", new CodePrimitiveExpression("Test Output."));
entry1.Statements.Add( method1 );
// Declares a label named "JumpToLabel" associated with a method to output a test string using Console.WriteLine.
CodeMethodInvokeExpression method2 = new CodeMethodInvokeExpression(
    new CodeTypeReferenceExpression("System.Console"), "WriteLine", new CodePrimitiveExpression("Output from labeled statement."));
CodeLabeledStatement label1 = new CodeLabeledStatement("JumpToLabel", new CodeExpressionStatement(method2) );
entry1.Statements.Add( label1 );

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

//    public class Type1
//    {
//
//        public static void Main()
//        {
//            goto JumpToLabel;
//            System.Console.WriteLine("Test Output");
//            JumpToLabel:
//            System.Console.WriteLine("Output from labeled statement.");
//        }
//    }
' Declares a type to contain the example code.
Dim type1 As New CodeTypeDeclaration("Type1")
' Declares an entry point method.
Dim entry1 As New CodeEntryPointMethod()
type1.Members.Add(entry1)
' Adds a goto statement to continue program flow at the "JumpToLabel" label.
Dim goto1 As New CodeGotoStatement("JumpToLabel")
entry1.Statements.Add(goto1)
' Invokes Console.WriteLine to print "Test Output", which is skipped by the goto statement.
Dim method1 As New CodeMethodInvokeExpression(New CodeTypeReferenceExpression("System.Console"), "WriteLine", New CodePrimitiveExpression("Test Output."))
entry1.Statements.Add(method1)
' Declares a label named "JumpToLabel" associated with a method to output a test string using Console.WriteLine.
Dim method2 As New CodeMethodInvokeExpression(New CodeTypeReferenceExpression("System.Console"), "WriteLine", New CodePrimitiveExpression("Output from labeled statement."))
Dim label1 As New CodeLabeledStatement("JumpToLabel", New CodeExpressionStatement(method2))
entry1.Statements.Add(label1)

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

'   Public Class Type1
'
'       Public Shared Sub Main()
'           GoTo JumpToLabel
'           System.Console.WriteLine("Test Output")
'           JumpToLabel:
'           System.Console.WriteLine("Output from labeled statement.")
'       End Sub
'   End Class

Hinweise

CodeLabeledStatement stellt eine Bezeichnung und optional eine zugeordnete Anweisung dar. Eine Bezeichnung kann verwendet werden, um das Ziel eines .CodeGotoStatement

Die Statement-Eigenschaft ist optional. Wenn Sie nur eine Bezeichnung erstellen möchten, lassen Sie die Statement Eigenschaft nicht initialisiert.

Hinweis

Nicht alle Sprachen unterstützen goto Anweisungen und Bezeichnungen. Daher sollten Sie testen, ob ein Codegenerator Anweisungen und Bezeichnungen unterstützt goto , indem Sie die Supports Methode mit dem GotoStatements Flag aufrufen.

Konstruktoren

Name Beschreibung
CodeLabeledStatement()

Initialisiert eine neue Instanz der CodeLabeledStatement-Klasse.

CodeLabeledStatement(String, CodeStatement)

Initialisiert eine neue Instanz der CodeLabeledStatement Klasse mithilfe des angegebenen Bezeichnungsnamens und der angegebenen Anweisung.

CodeLabeledStatement(String)

Initialisiert eine neue Instanz der CodeLabeledStatement Klasse mithilfe des angegebenen Bezeichnungsnamens.

Eigenschaften

Name Beschreibung
EndDirectives

Ruft ein CodeDirectiveCollection Objekt ab, das Enddirektiven enthält.

(Geerbt von CodeStatement)
Label

Dient zum Abrufen oder Festlegen des Namens der Bezeichnung.

LinePragma

Ruft die Zeile ab, in der die Code-Anweisung auftritt, oder legt sie fest.

(Geerbt von CodeStatement)
StartDirectives

Ruft ein CodeDirectiveCollection Objekt ab, das Startdirektiven enthält.

(Geerbt von CodeStatement)
Statement

Ruft die optionale zugeordnete Anweisung ab oder legt sie fest.

UserData

Ruft die vom Benutzer definierbaren Daten für das aktuelle Objekt ab.

(Geerbt von CodeObject)

Methoden

Name Beschreibung
Equals(Object)

Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht.

(Geerbt von Object)
GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Gilt für:

Weitere Informationen