C# TypeInfo IsExplicitLayout
Description
TypeInfo IsExplicitLayout
Gets a value indicating whether
the fields of the current type are laid out at explicitly specified offsets.
Syntax
TypeInfo.IsExplicitLayout
has the following syntax.
public bool IsExplicitLayout { get; }
Example
The following example creates an instance of a type and displays the value of its IsExplicitLayout property. It uses the MySystemTime class, which is also in the code example for StructLayoutAttribute.
/*w w w . j av a2 s . co m*/
using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Explicit, Size=16, CharSet=CharSet.Ansi)]
public class MySystemTime
{
[FieldOffset(0)]public ushort wYear;
[FieldOffset(2)]public ushort wMonth;
[FieldOffset(4)]public ushort wDayOfWeek;
[FieldOffset(6)]public ushort wDay;
[FieldOffset(8)]public ushort wHour;
[FieldOffset(10)]public ushort wMinute;
[FieldOffset(12)]public ushort wSecond;
[FieldOffset(14)]public ushort wMilliseconds;
}
public class Program
{
public static void Main(string[] args)
{
Type t = typeof(MySystemTime);
Console.WriteLine(t.IsExplicitLayout);
}
}
The code above generates the following result.