Type.IsLayoutSequential Propiedad

Definición

Obtiene un valor que indica si los campos del tipo actual se disponen secuencialmente, en el orden que se definieron o emitieron en los metadatos.Gets a value indicating whether the fields of the current type are laid out sequentially, in the order that they were defined or emitted to the metadata.

public:
 property bool IsLayoutSequential { bool get(); };
public bool IsLayoutSequential { get; }
member this.IsLayoutSequential : bool
Public ReadOnly Property IsLayoutSequential As Boolean

Valor de propiedad

Boolean

true si la propiedad Attributes del tipo actual incluye SequentialLayout; en caso contrario, es false.true if the Attributes property of the current type includes SequentialLayout; otherwise, false.

Implementaciones

Ejemplos

En el ejemplo siguiente se crea una instancia de una clase para la que se ha LayoutKind.Sequential establecido el valor de enumeración en la StructLayoutAttribute clase, se comprueba la IsLayoutSequential propiedad y se muestra el resultado.The following example creates an instance of a class for which the LayoutKind.Sequential enumeration value in the StructLayoutAttribute class has been set, checks for the IsLayoutSequential property, and displays the result.

#using <System.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;
ref class MyTypeSequential1{};


[StructLayoutAttribute(LayoutKind::Sequential)]
ref class MyTypeSequential2{};

int main()
{
   try
   {
      
      // Create an instance of myTypeSeq1.
      MyTypeSequential1^ myObj1 = gcnew MyTypeSequential1;
      
      // Check for and display the SequentialLayout attribute.
      Console::WriteLine( "\nThe object myObj1 has IsLayoutSequential: {0}.", myObj1->GetType()->IsLayoutSequential );
      
      // Create an instance of 'myTypeSeq2' class.
      MyTypeSequential2^ myObj2 = gcnew MyTypeSequential2;
      
      // Check for and display the SequentialLayout attribute.
      Console::WriteLine( "\nThe object myObj2 has IsLayoutSequential: {0}.", myObj2->GetType()->IsLayoutSequential );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "\nAn exception occurred: {0}", e->Message );
   }

}

using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.InteropServices;
class MyTypeSequential1
{
}
[StructLayoutAttribute(LayoutKind.Sequential)]
class MyTypeSequential2
{
    public static void Main(string []args)
    {
        try
        {
            // Create an instance of myTypeSeq1.
            MyTypeSequential1 myObj1 = new MyTypeSequential1();
            Type myTypeObj1 = myObj1.GetType();
            // Check for and display the SequentialLayout attribute.
            Console.WriteLine("\nThe object myObj1 has IsLayoutSequential: {0}.", myObj1.GetType().IsLayoutSequential);
            // Create an instance of 'myTypeSeq2' class.
            MyTypeSequential2 myObj2 = new MyTypeSequential2();
            Type myTypeObj2 = myObj2.GetType();
            // Check for and display the SequentialLayout attribute.
            Console.WriteLine("\nThe object myObj2 has IsLayoutSequential: {0}.", myObj2.GetType().IsLayoutSequential);
        }
        catch(Exception e)
        {
            Console.WriteLine("\nAn exception occurred: {0}", e.Message);
        }
    }
}
Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.InteropServices

Class MyTypeSequential1
End Class
<StructLayoutAttribute(LayoutKind.Sequential)> Class MyTypeSequential2
    Public Shared Sub Main()
        Try
            ' Create an instance of MyTypeSequential1.
            Dim myObj1 As New MyTypeSequential1()
            Dim myTypeObj1 As Type = myObj1.GetType()
            ' Check for and display the SequentialLayout attribute.
            Console.WriteLine(ControlChars.Cr + "The object myObj1 has IsLayoutSequential: {0}.", myObj1.GetType().IsLayoutSequential.ToString())
            ' Create an instance of MyTypeSequential2.
            Dim myObj2 As New MyTypeSequential2()
            Dim myTypeObj2 As Type = myObj2.GetType()
            ' Check for and display the SequentialLayout attribute.
            Console.WriteLine(ControlChars.Cr + "The object myObj2 has IsLayoutSequential: {0}.", myObj2.GetType().IsLayoutSequential.ToString())
        Catch e As Exception
            Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString())
        End Try
    End Sub
End Class

Comentarios

Esta propiedad se proporciona como una comodidad.This property is provided as a convenience. Como alternativa, puede usar el TypeAttributes.LayoutMask valor de enumeración para seleccionar los atributos de diseño de tipo y, a continuación, probar si TypeAttributes.SequentialLayout está establecido.Alternatively, you can use the TypeAttributes.LayoutMask enumeration value to select the type layout attributes, and then test whether TypeAttributes.SequentialLayout is set. Los TypeAttributes.AutoLayout TypeAttributes.ExplicitLayout TypeAttributes.SequentialLayout valores de enumeración, y indican el modo en que los campos del tipo se disponen en la memoria.The TypeAttributes.AutoLayout, TypeAttributes.ExplicitLayout, and TypeAttributes.SequentialLayout enumeration values indicate the way the fields of the type are laid out in memory.

En el caso de los tipos dinámicos, puede especificar TypeAttributes.SequentialLayout al crear el tipo.For dynamic types, you can specify TypeAttributes.SequentialLayout when you create the type. En el código, aplique el StructLayoutAttribute atributo con el LayoutKind.Sequential valor de enumeración al tipo para especificar que el diseño es secuencial.In code, apply the StructLayoutAttribute attribute with the LayoutKind.Sequential enumeration value to the type, to specify that layout is sequential.

Nota

No se puede usar el GetCustomAttributes método para determinar si se StructLayoutAttribute ha aplicado a un tipo.You cannot use the GetCustomAttributes method to determine whether the StructLayoutAttribute has been applied to a type.

Para obtener más información, consulte la sección 9.1.2 de la especificación de la documentación de Common Language Infrastructure (CLI), "Partition II: definición y semántica de los metadatos".For more information, see section 9.1.2 of the specification for the Common Language Infrastructure (CLI) documentation, "Partition II: Metadata Definition and Semantics". La documentación está disponible en línea; vea ECMA C# and Common Language Infrastructure Standards (Estándares de ECMA C# y Common Language Infrastructure) en MSDN y Standard ECMA-335 - Common Language Infrastructure (CLI) (Estándar ECMA-335: Common Language Infrastructure [CLI]) en el sitio web de Ecma International.The documentation is available online; see ECMA C# and Common Language Infrastructure Standards on MSDN and Standard ECMA-335 - Common Language Infrastructure (CLI) on the Ecma International Web site.

Si el actual Type representa un tipo genérico construido, esta propiedad se aplica a la definición de tipo genérico a partir de la cual se construyó el tipo.If the current Type represents a constructed generic type, this property applies to the generic type definition from which the type was constructed. Por ejemplo, si el actual Type representa MyGenericType<int> ( MyGenericType(Of Integer) en Visual Basic), el valor de esta propiedad viene determinado por MyGenericType<T> .For example, if the current Type represents MyGenericType<int> (MyGenericType(Of Integer) in Visual Basic), the value of this property is determined by MyGenericType<T>.

Si el actual Type representa un parámetro de tipo en la definición de un tipo genérico o de un método genérico, esta propiedad siempre devuelve false .If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false.

Se aplica a

Consulte también