Type.IsLayoutSequential Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recebe um valor que indica se os campos do tipo atual estão dispostos sequencialmente, pela ordem em que foram definidos ou emitidos para os metadados.
public:
property bool IsLayoutSequential { bool get(); };
public bool IsLayoutSequential { get; }
member this.IsLayoutSequential : bool
Public ReadOnly Property IsLayoutSequential As Boolean
Valor de Propriedade
true se a Attributes propriedade do tipo atual incluir SequentialLayout; caso contrário, false.
Implementações
Exemplos
O exemplo seguinte cria uma instância de uma classe para a qual o LayoutKind.Sequential valor de enumeração na StructLayoutAttribute classe foi definido, verifica a IsLayoutSequential propriedade e apresenta o resultado.
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);
}
}
}
open System.Runtime.InteropServices
type MyTypeSequential1 = struct end
[<StructLayoutAttribute(LayoutKind.Sequential)>]
type MyTypeSequential2 = struct end
try
// Create an instance of myTypeSeq1.
let myObj1 = MyTypeSequential1()
let myTypeObj1 = myObj1.GetType()
// Check for and display the SequentialLayout attribute.
printfn $"\nThe object myObj1 has IsLayoutSequential: {myTypeObj1.IsLayoutSequential}."
// Create an instance of 'myTypeSeq2' class.
let myObj2 = MyTypeSequential2()
let myTypeObj2 = myObj2.GetType()
// Check for and display the SequentialLayout attribute.
printfn $"\nThe object myObj2 has IsLayoutSequential: {myTypeObj2.IsLayoutSequential}."
with e ->
printfn $"\nAn exception occurred: {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
Observações
Esta propriedade é fornecida por conveniência. Alternativamente, pode usar o TypeAttributes.LayoutMask valor de enumeração para selecionar os atributos de layout de tipos e depois testar se TypeAttributes.SequentialLayout está definido. Os TypeAttributes.AutoLayoutvalores , TypeAttributes.ExplicitLayout, e TypeAttributes.SequentialLayout de enumeração indicam a forma como os campos do tipo estão dispostos na memória.
Para tipos dinâmicos, podes especificar TypeAttributes.SequentialLayout quando crias o tipo. No código, aplica-se o StructLayoutAttribute atributo com o LayoutKind.Sequential valor de enumeração ao tipo, para especificar que o layout é sequencial.
Note
Não pode usar o GetCustomAttributes método para determinar se o StructLayoutAttribute foi aplicado a um tipo.
Para mais informações, consulte a secção 9.1.2 da especificação para a documentação da Common Language Infrastructure (CLI), "Partição II: Metadata Definition and Semantics".
Se a corrente Type representa um tipo genérico construído, esta propriedade aplica-se à definição genérica de tipo a partir da qual o tipo foi construído. Por exemplo, se o atual Type representa MyGenericType<int> (MyGenericType(Of Integer) em Visual Basic), o valor desta propriedade é determinado por MyGenericType<T>.
Se a corrente Type representa um parâmetro de tipo na definição de um tipo genérico ou método genérico, esta propriedade devolve falsesempre .