Ler en inglés

Compartir por


CodeLabeledStatement Clase

Definición

Representa una instrucción con etiqueta o una etiqueta independiente.

C#
public class CodeLabeledStatement : System.CodeDom.CodeStatement
C#
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeLabeledStatement : System.CodeDom.CodeStatement
Herencia
CodeLabeledStatement
Atributos

Ejemplos

En el código de ejemplo siguiente se muestra el uso de CodeGotoStatement y un para CodeLabeledStatement redirigir el flujo de programa.

C#
// 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.");
//        }
//    }

Comentarios

CodeLabeledStatement representa una etiqueta y, opcionalmente, una instrucción asociada. Se puede usar una etiqueta para indicar el destino de .CodeGotoStatement

La propiedad Statement es opcional. Para crear solo una etiqueta, deje la Statement propiedad sin inicializar.

Nota

No todos los lenguajes admiten goto instrucciones y etiquetas, por lo que debe probar si un generador de código admite goto instrucciones y etiquetas llamando al Supports método con la GotoStatements marca .

Constructores

CodeLabeledStatement()

Inicializa una nueva instancia de la clase CodeLabeledStatement.

CodeLabeledStatement(String)

Inicializa una nueva instancia de la clase CodeLabeledStatement con el nombre de etiqueta especificado.

CodeLabeledStatement(String, CodeStatement)

Inicializa una nueva instancia de la clase CodeLabeledStatement con el nombre de la etiqueta e instrucción especificadas.

Propiedades

EndDirectives

Obtiene un objeto CodeDirectiveCollection que contiene las directivas End.

(Heredado de CodeStatement)
Label

Obtiene o establece el nombre de la etiqueta.

LinePragma

Obtiene o establece la línea en la que se ejecuta la instrucción de código.

(Heredado de CodeStatement)
StartDirectives

Obtiene un objeto CodeDirectiveCollection que contiene las directivas Start.

(Heredado de CodeStatement)
Statement

Obtiene o establece la instrucción asociada opcional.

UserData

Obtiene los datos definibles por el usuario para el objeto actual.

(Heredado de CodeObject)

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a

Produto Versións
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Consulte también