Type::StructLayoutAttribute Property

Gets a StructLayoutAttribute that describes the layout of the current type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public:
virtual property StructLayoutAttribute^ StructLayoutAttribute {
	StructLayoutAttribute^ get ();
}

Property Value

Type: System.Runtime.InteropServices::StructLayoutAttribute
Gets a StructLayoutAttribute that describes the gross layout features of the current type.

ExceptionCondition
NotSupportedException

The invoked method is not supported in the base class.

StructLayoutAttribute is not returned by the GetCustomAttributes method. Instead, use this property to get it.

The following code example first defines a class, a structure, and a structure with special layout attributes (the structures are nested within the class). 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;
}



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft