Type.StructLayoutAttribute Type.StructLayoutAttribute Type.StructLayoutAttribute Type.StructLayoutAttribute Property

정의

현재 형식의 레이아웃을 설명하는 StructLayoutAttribute를 가져옵니다.Gets a StructLayoutAttribute that describes the layout of the current type.

public:
 virtual property System::Runtime::InteropServices::StructLayoutAttribute ^ StructLayoutAttribute { System::Runtime::InteropServices::StructLayoutAttribute ^ get(); };
public virtual System.Runtime.InteropServices.StructLayoutAttribute StructLayoutAttribute { get; }
member this.StructLayoutAttribute : System.Runtime.InteropServices.StructLayoutAttribute
Public Overridable ReadOnly Property StructLayoutAttribute As StructLayoutAttribute

속성 값

현재 형식의 전체 레이아웃 기능을 설명하는 StructLayoutAttribute를 가져옵니다.Gets a StructLayoutAttribute that describes the gross layout features of the current type.

예외

호출된 메서드가 기본 클래스에서 지원되지 않습니다.The invoked method is not supported in the base class.

예제

다음 코드 예제는 먼저 클래스, 구조체 및 특별 한 레이아웃이 특성 (구조 내에 중첩 된 클래스)를 사용 하 여 구조를 정의 합니다.The following code example first defines a class, a structure, and a structure with special layout attributes (the structures are nested within the class). 이 예제에서는 다음 사용 합니다 StructLayoutAttribute 속성을를 StructLayoutAttribute 각 형식과 표시 특성의 속성에 대 한 합니다.The example then uses the StructLayoutAttribute property to obtain a StructLayoutAttribute for each type, and displays the properties of the attributes.

using namespace System;
using namespace System::Runtime::InteropServices;
value struct Test1
{
public:
   Byte B1;
   short S;
   Byte B2;
};


[StructLayout(LayoutKind::Explicit,Pack=1)]
value struct Test2
{
public:

   [FieldOffset(0)]
   Byte B1;

   [FieldOffset(1)]
   short S;

   [FieldOffset(3)]
   Byte B2;
};

static void DisplayLayoutAttribute( StructLayoutAttribute^ sla )
{
   Console::WriteLine( L"\r\nCharSet: {0}\r\n   Pack: {1}\r\n   Size: {2}\r\n  Value: {3}", sla->CharSet, sla->Pack, sla->Size, sla->Value );
}

int main()
{
   DisplayLayoutAttribute( Test1::typeid->StructLayoutAttribute );
   return 0;
}

using System;
using System.Runtime.InteropServices;

public class Example
{
    public static void Main()
    {
        DisplayLayoutAttribute(typeof(Example).StructLayoutAttribute);
        DisplayLayoutAttribute(typeof(Test1).StructLayoutAttribute);
        DisplayLayoutAttribute(typeof(Test2).StructLayoutAttribute);
    }

    private static void DisplayLayoutAttribute(StructLayoutAttribute sla)
    {
        Console.WriteLine("\r\nCharSet: "+sla.CharSet.ToString()+"\r\n   Pack: "+sla.Pack.ToString()+"\r\n   Size: "+sla.Size.ToString()+"\r\n  Value: "+sla.Value.ToString());
    }
    public struct Test1
    {
        public byte B1;
        public short S;
        public byte B2;
    }
    [StructLayout(LayoutKind.Explicit, Pack=1)] public struct Test2
    {
        [FieldOffset(0)] public byte B1;
        [FieldOffset(1)] public short S;
        [FieldOffset(3)] public byte B2;
    }
}
Imports System.Runtime.InteropServices

Public Class Example
    Public Shared Sub Main()
        DisplayLayoutAttribute(GetType(Example).StructLayoutAttribute)
        DisplayLayoutAttribute(GetType(Test1).StructLayoutAttribute)
        DisplayLayoutAttribute(GetType(Test2).StructLayoutAttribute)
    End Sub

    Private Shared Sub DisplayLayoutAttribute( _
        ByVal sla As StructLayoutAttribute)
        Console.WriteLine(vbCrLf & "CharSet: " & sla.CharSet.ToString() _
            & vbCrLf & "   Pack: " & sla.Pack.ToString() _
            & vbCrLf & "   Size: " & sla.Size.ToString() _
            & vbCrLf & "  Value: " & sla.Value.ToString())
    End Sub

    Public Structure Test1
        Public B1 As Byte
        Public S As Short
        Public B2 As Byte
    End Structure

    <StructLayout(LayoutKind.Explicit, Pack:=1)> _
    Public Structure Test2
        <FieldOffset(0)> Public B1 As Byte
        <FieldOffset(1)> Public S As Short
        <FieldOffset(3)> Public B2 As Byte
    End Structure
End Class

설명

StructLayoutAttribute 반환 하지 않습니다는 GetCustomAttributes 메서드.StructLayoutAttribute is not returned by the GetCustomAttributes method. 대신,이 속성을 사용 합니다.Instead, use this property to get it.

적용 대상

추가 정보