Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.IsExplicitLayout Property

Gets a value indicating whether the class layout attribute ExplicitLayout is selected for the Type.

[Visual Basic]
Public ReadOnly Property IsExplicitLayout As Boolean
[C#]
public bool IsExplicitLayout {get;}
[C++]
public: __property bool get_IsExplicitLayout();
[JScript]
public function get IsExplicitLayout() : Boolean;

Property Value

true if the class layout attribute ExplicitLayout is selected for the Type; otherwise, false.

Remarks

The LayoutMask is used to select the class layout attributes. The class layout attributes (AutoLayout, SequentialLayout and ExplicitLayout) define how the fields of the class instance are laid out in memory.

Classes marked with the ExplicitLayout attribute cause the loader to ignore field sequence and to use the explicit layout rules provided, in the form of field offsets, overall class size and alignment, or all of these.

Use the ExplicitLayout attribute to specify the offsets at which each field starts, or to specify the overall size and, optionally, the packing size of the objects of the class. The packing size is the empty memory space between fields and must be 1, 2, 4, 8 or 16 bytes.

Example

[Visual Basic, C#, C++] The following example creates an instance of the specified type and displays the IsExplicitLayout property of the MyDemoAttribute class.

[Visual Basic] 
Imports System
Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic
'The class to be tested for the ExplicitLayout property.
<StructLayoutAttribute(LayoutKind.Explicit)> Public Class MyDemoAttribute
End Class 'MyDemoAttribute
Public Class MyTypeClass
    Public Shared Sub Main()
        MyIsExplicitLayoutMethod("MyDemoAttribute")
    End Sub 'Main
    Public Shared Sub MyIsExplicitLayoutMethod(ByVal typeName As String)
        Try
            'Create an instance of the type using the GetType method.
            Dim myType As Type = Type.GetType(typeName)
            ' Get and display the IsExplicitLayout property.
            Console.WriteLine(ControlChars.Cr + "The IsExplicitLayout property of the MyDemoAttribute instance is {0}.", myType.IsExplicitLayout.ToString())
        Catch e As Exception
            Console.WriteLine("An exception occurred: {0}.", e.Message.ToString())
        End Try
    End Sub 'MyIsExplicitLayoutMethod
End Class 'MyTypeClass

[C#] 
using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.InteropServices;
//The class to be tested for the ExplicitLayout property.
[StructLayoutAttribute(LayoutKind.Explicit)]
public class MyDemoAttribute
{
}
public class MyTypeClass
{
    public static void Main(string[] args)
    {
        MyIsExplicitLayoutMethod("MyDemoAttribute");     
    }
    public static void MyIsExplicitLayoutMethod(string typeName)
    {
        try
        {
            // Create an instance of the type using the GetType method.
            Type  myType=Type.GetType(typeName);
            // Get and display the IsExplicitLayout property.
            Console.WriteLine("\nThe IsExplicitLayout property of the MyDemoAttribute instance is {0}.", myType.IsExplicitLayout); 
        }
        catch(Exception e)
        {
            Console.WriteLine("\nAn exception occurred: {0}.", e.Message);
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;

//The class to be tested for the ExplicitLayout property.
[StructLayoutAttribute(LayoutKind::Explicit)]
public __gc class MyDemoAttribute {
};

void MyIsExplicitLayoutMethod(String* typeName) {
   try {
      // Create an instance of the type using the GetType method.
      Type*  myType=Type::GetType(typeName);
      // Get and display the IsExplicitLayout property.
      Console::WriteLine(S"\nThe IsExplicitLayout property of the MyDemoAttribute instance is {0}.",
         __box( myType->IsExplicitLayout));
   } catch (Exception* e) {
      Console::WriteLine(S"\nAn exception occurred: {0}.", e->Message);
   }
}

int main() {

   MyIsExplicitLayoutMethod(S"MyDemoAttribute");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | TypeAttributes | IsAutoLayout | IsLayoutSequential | Metadata Overview

Show:
© 2014 Microsoft