CodeGotoStatement Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Representa una goto instrucción .
public ref class CodeGotoStatement : System::CodeDom::CodeStatement
public class CodeGotoStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeGotoStatement : System.CodeDom.CodeStatement
type CodeGotoStatement = class
inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeGotoStatement = class
inherit CodeStatement
Public Class CodeGotoStatement
Inherits CodeStatement
- Herencia
- Atributos
Ejemplos
En el código de ejemplo siguiente se muestra el uso de y un CodeLabeledStatement para redirigir el flujo de CodeGotoStatement programa.
// 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
Comentarios
CodeGotoStatement se puede usar para representar una goto instrucción , que se usa en algunos lenguajes para redirigir el flujo de programa a una etiqueta especificada.
La Label propiedad indica el nombre de la etiqueta en la que se va a continuar la ejecución del programa.
Nota:
No todos los idiomas admiten goto instrucciones. Llame al Supports método con la GotoStatements marca para determinar si un generador de código admite instrucciones goto .
Constructores
| Nombre | Description |
|---|---|
| CodeGotoStatement() |
Inicializa una nueva instancia de la clase CodeGotoStatement. |
| CodeGotoStatement(String) |
Inicializa una nueva instancia de la CodeGotoStatement clase utilizando el nombre de etiqueta especificado. |
Propiedades
| Nombre | Description |
|---|---|
| EndDirectives |
Obtiene un CodeDirectiveCollection objeto que contiene directivas end. (Heredado de CodeStatement) |
| Label |
Obtiene o establece el nombre de la etiqueta en la que se va a continuar la ejecución del programa. |
| LinePragma |
Obtiene o establece la línea en la que se produce la instrucción de código. (Heredado de CodeStatement) |
| StartDirectives |
Obtiene un CodeDirectiveCollection objeto que contiene directivas start. (Heredado de CodeStatement) |
| UserData |
Obtiene los datos definibles por el usuario para el objeto actual. (Heredado de CodeObject) |
Métodos
| Nombre | Description |
|---|---|
| Equals(Object) |
Determina si el objeto especificado es igual al objeto actual. (Heredado de Object) |
| GetHashCode() |
Actúa como función hash predeterminada. (Heredado de Object) |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |