CodeLabeledStatement Klasa
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Reprezentuje instrukcję z etykietą lub etykietę autonomiczną.
public ref 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
[<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
- Dziedziczenie
- Atrybuty
Przykłady
Poniższy przykładowy kod demonstruje użycie elementu CodeGotoStatement i , CodeLabeledStatement aby przekierować przepływ programu.
// 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
Uwagi
CodeLabeledStatement reprezentuje etykietę i opcjonalnie skojarzona instrukcja. Etykietę można użyć do wskazania elementu docelowego elementu CodeGotoStatement.
Właściwość Statement jest opcjonalna. Aby utworzyć tylko etykietę, pozostaw Statement niezainicjowaną właściwość.
Note
Nie wszystkie języki obsługują goto instrukcje i etykiety, dlatego należy sprawdzić, czy generator kodu obsługuje goto instrukcje i etykiety, wywołując Supports metodę z flagą GotoStatements .
Konstruktory
| Nazwa | Opis |
|---|---|
| CodeLabeledStatement() |
Inicjuje nowe wystąpienie klasy CodeLabeledStatement. |
| CodeLabeledStatement(String, CodeStatement) |
Inicjuje nowe wystąpienie CodeLabeledStatement klasy przy użyciu określonej nazwy etykiety i instrukcji. |
| CodeLabeledStatement(String) |
Inicjuje nowe wystąpienie CodeLabeledStatement klasy przy użyciu określonej nazwy etykiety. |
Właściwości
| Nazwa | Opis |
|---|---|
| EndDirectives |
CodeDirectiveCollection Pobiera obiekt zawierający dyrektywy końcowe. (Odziedziczone po CodeStatement) |
| Label |
Pobiera lub ustawia nazwę etykiety. |
| LinePragma |
Pobiera lub ustawia wiersz, w którym występuje instrukcja kodu. (Odziedziczone po CodeStatement) |
| StartDirectives |
CodeDirectiveCollection Pobiera obiekt zawierający dyrektywy startowe. (Odziedziczone po CodeStatement) |
| Statement |
Pobiera lub ustawia opcjonalną skojarzną instrukcję. |
| UserData |
Pobiera dane zdefiniowane przez użytkownika dla bieżącego obiektu. (Odziedziczone po CodeObject) |
Metody
| Nazwa | Opis |
|---|---|
| Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Odziedziczone po Object) |
| GetHashCode() |
Służy jako domyślna funkcja skrótu. (Odziedziczone po Object) |
| GetType() |
Type Pobiera wartość bieżącego wystąpienia. (Odziedziczone po Object) |
| MemberwiseClone() |
Tworzy płytkią kopię bieżącego Objectelementu . (Odziedziczone po Object) |
| ToString() |
Zwraca ciąg reprezentujący bieżący obiekt. (Odziedziczone po Object) |