CodeLabeledStatement Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Representerar en etikettsats eller en fristående etikett.
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
- Arv
- Attribut
Exempel
Följande exempelkod visar användning av ett CodeGotoStatement och ett CodeLabeledStatement för att omdirigera programflödet.
// 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
Kommentarer
CodeLabeledStatement representerar en etikett och eventuellt en associerad instruktion. En etikett kan användas för att ange målet för en CodeGotoStatement.
Egenskapen Statement är valfri. Om du bara vill skapa en etikett lämnar du Statement egenskapen oinitierad.
Note
Alla språk stöder goto inte instruktioner och etiketter, så du bör testa om en kodgenerator stöder goto instruktioner och etiketter genom att anropa Supports metoden med GotoStatements flaggan.
Konstruktorer
| Name | Description |
|---|---|
| CodeLabeledStatement() |
Initierar en ny instans av CodeLabeledStatement klassen. |
| CodeLabeledStatement(String, CodeStatement) |
Initierar en ny instans av CodeLabeledStatement klassen med det angivna etikettnamnet och -instruktionen. |
| CodeLabeledStatement(String) |
Initierar en ny instans av CodeLabeledStatement klassen med det angivna etikettnamnet. |
Egenskaper
| Name | Description |
|---|---|
| EndDirectives |
Hämtar ett CodeDirectiveCollection objekt som innehåller slutdirektiv. (Ärvd från CodeStatement) |
| Label |
Hämtar eller anger namnet på etiketten. |
| 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) |
| Statement |
Hämtar eller anger den valfria associerade instruktionen. |
| 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) |