CodeLabeledStatement-Klasse
Stellt eine Anweisung mit Marke oder eine eigenständige Marke dar.
Namespace: System.CodeDom
Assembly: System (in system.dll)
Syntax
'Declaration
<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class CodeLabeledStatement
Inherits CodeStatement
'Usage
Dim instance As CodeLabeledStatement
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeLabeledStatement : CodeStatement
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
public ref class CodeLabeledStatement : public CodeStatement
/** @attribute SerializableAttribute() */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute ComVisibleAttribute(true) */
public class CodeLabeledStatement extends CodeStatement
SerializableAttribute
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
ComVisibleAttribute(true)
public class CodeLabeledStatement extends CodeStatement
Hinweise
CodeLabeledStatement stellt eine Sprungmarke und optional eine zugeordnete Anweisung dar. Mit einer Sprungmarke kann das Ziel einer CodeGotoStatement angegeben werden.
Die Statement-Eigenschaft ist optional. Initialisieren Sie die Statement-Eigenschaft nicht, wenn Sie nur eine Sprungmarke erstellen möchten.
Hinweis
goto-Anweisungen und Sprungmarken werden nicht von allen Sprachen unterstützt. Testen Sie also zunächst, ob ein Code-Generator goto-Anweisungen und Sprungmarken unterstützt, indem Sie die Supports-Methode mit dem GotoStatements-Flag aufrufen.
Beispiel
Im folgenden Beispielcode wird veranschaulicht, wie mit einem CodeGotoStatement und einem CodeLabeledStatement der Programmablauf umgeleitet wird.
' 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
// 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.
CodeTypeDeclaration^ type1 = gcnew CodeTypeDeclaration( "Type1" );
// Declares an entry point method.
CodeEntryPointMethod^ entry1 = gcnew CodeEntryPointMethod;
type1->Members->Add( entry1 );
// Adds a goto statement to continue program flow at the "JumpToLabel" label.
CodeGotoStatement^ goto1 = gcnew CodeGotoStatement( "JumpToLabel" );
entry1->Statements->Add( goto1 );
// Invokes Console.WriteLine to print "Test Output", which is skipped by the goto statement.
array<CodeExpression^>^temp = {gcnew CodePrimitiveExpression( "Test Output." )};
CodeMethodInvokeExpression^ method1 = gcnew CodeMethodInvokeExpression( gcnew CodeTypeReferenceExpression( "System.Console" ),"WriteLine",temp );
entry1->Statements->Add( method1 );
// Declares a label named "JumpToLabel" associated with a method to output a test string using Console.WriteLine.
array<CodeExpression^>^temp2 = {gcnew CodePrimitiveExpression( "Output from labeled statement." )};
CodeMethodInvokeExpression^ method2 = gcnew CodeMethodInvokeExpression( gcnew CodeTypeReferenceExpression( "System.Console" ),"WriteLine",temp2 );
CodeLabeledStatement^ label1 = gcnew CodeLabeledStatement( "JumpToLabel",gcnew 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.
CodeTypeDeclaration type1 = new CodeTypeDeclaration("Type1");
// Declares an entry point method.
CodeEntryPointMethod entry1 = new CodeEntryPointMethod();
type1.get_Members().Add(entry1);
// Adds a goto statement to continue program flow at the
// "JumpToLabel" label.
CodeGotoStatement goto1 = new CodeGotoStatement("JumpToLabel");
entry1.get_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[] { new
CodePrimitiveExpression("Test Output.") });
entry1.get_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[]
{ new CodePrimitiveExpression("Output from labeled statement.") });
CodeLabeledStatement label1 = new CodeLabeledStatement("JumpToLabel",
new CodeExpressionStatement(method2));
entry1.get_Statements().Add(label1);
// A VJ# 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.");
// } //main
// } //Type1
Vererbungshierarchie
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeLabeledStatement
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
CodeLabeledStatement-Member
System.CodeDom-Namespace
CodeGotoStatement-Klasse