Export (0) Print
Expand All

Type.IsExplicitLayout Property

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

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

public bool IsExplicitLayout { get; }
/** @property */
public final boolean get_IsExplicitLayout ()

public final function get IsExplicitLayout () : boolean

Property Value

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

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.

If the current Type represents a constructed generic type, this property applies to the generic type definition from which the type was constructed. 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>.

If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false.

The following example creates an instance of the specified type and displays the IsExplicitLayout property of the MyDemoAttribute class.

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 Demo
{
}
public class MyTypeClass
{
    public static void Main(string[] args)
    {
        // Create an instance of the type using the GetType method.
        Type  myType = typeof(Demo);
        // Get and display the IsExplicitLayout property.
        Console.WriteLine("\nThe IsExplicitLayout property of the Demo type is {0}.", 
            myType.IsExplicitLayout); 
    }
}

import System.*;
import System.Reflection.*;
import System.ComponentModel.*;
import System.Runtime.InteropServices.*;

//The class to be tested for the ExplicitLayout property.
/** @attribute StructLayoutAttribute(LayoutKind.Explicit)
 */
public class MyDemoAttribute
{
} //MyDemoAttribute

public class MyTypeClass
{
    public static void main(String[] args)
    {
        MyIsExplicitLayoutMethod("MyDemoAttribute");
    } //main

    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}.", System.Convert.
                ToString(myType.get_IsExplicitLayout()));
        }
        catch (System.Exception e) {
            Console.WriteLine("\nAn exception occurred: {0}.", e.get_Message());
        }
    } //MyIsExplicitLayoutMethod
} //MyTypeClass

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft