Type.IsExplicitLayout Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt een waarde opgehaald die aangeeft of de velden van het huidige type zijn ingedeeld bij expliciet opgegeven offsets.
public:
property bool IsExplicitLayout { bool get(); };
public bool IsExplicitLayout { get; }
member this.IsExplicitLayout : bool
Public ReadOnly Property IsExplicitLayout As Boolean
Waarde van eigenschap
trueals de Attributes eigenschap van het huidige type is opgenomenExplicitLayout; anders. false
Implementeringen
Voorbeelden
In het volgende voorbeeld wordt een exemplaar van een type gemaakt en wordt de waarde van IsExplicitLayout de eigenschap weergegeven. Hierbij wordt de MySystemTime klasse gebruikt, die ook in het codevoorbeeld voor StructLayoutAttribute.
using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.InteropServices;
// Class to test for the ExplicitLayout property.
[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)
{
// Create an instance of the type using the GetType method.
Type t = typeof(MySystemTime);
// Get and display the IsExplicitLayout property.
Console.WriteLine("\nIsExplicitLayout for MySystemTime is {0}.",
t.IsExplicitLayout);
}
}
open System.Runtime.InteropServices
// Class to test for the ExplicitLayout property.
[<StructLayout(LayoutKind.Explicit, Size=16, CharSet=CharSet.Ansi)>]
type MySystemTime =
[<FieldOffset 0>] val public wYear: uint16
[<FieldOffset 2>] val public wMonth: uint16
[<FieldOffset 4>] val public wDayOfWeek: uint16
[<FieldOffset 6>] val public wDay: uint16
[<FieldOffset 8>] val public wHour: uint16
[<FieldOffset 10>] val public wMinute: uint16
[<FieldOffset 12>] val public wSecond: uint16
[<FieldOffset 14>] val public wMilliseconds: uint16
// Create an instance of the type using the GetType method.
let t = typeof<MySystemTime>
// Get and display the IsExplicitLayout property.
printfn $"\nIsExplicitLayout for MySystemTime is {t.IsExplicitLayout}."
Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.InteropServices
'Class to test for the ExplicitLayout property.
<StructLayout(LayoutKind.Explicit, Size := 16, CharSet := CharSet.Ansi)> _
Public Class MySystemTime
<FieldOffset(0)> Public wYear As Short
<FieldOffset(2)> Public wMonth As Short
<FieldOffset(4)> Public wDayOfWeek As Short
<FieldOffset(6)> Public wDay As Short
<FieldOffset(8)> Public wHour As Short
<FieldOffset(10)> Public wMinute As Short
<FieldOffset(12)> Public wSecond As Short
<FieldOffset(14)> Public wMilliseconds As Short
End Class
Public Class Program
Public Shared Sub Main()
'Create an instance of type using the GetType method.
Dim t As Type = GetType(MySystemTime)
' Get and display the IsExplicitLayout property.
Console.WriteLine(vbCrLf & "IsExplicitLayout for MySystemTime is {0}.", _
t.IsExplicitLayout)
End Sub
End Class
Opmerkingen
Deze accommodatie is als gemak beschikbaar. U kunt ook de TypeAttributes.LayoutMask opsommingswaarde gebruiken om de typeindelingskenmerken te selecteren en vervolgens te testen of TypeAttributes.ExplicitLayout deze is ingesteld. De TypeAttributes.AutoLayoutwaarden , TypeAttributes.ExplicitLayouten TypeAttributes.SequentialLayout opsomming geven aan hoe de velden van het type in het geheugen worden ingedeeld.
Voor dynamische typen kunt u opgeven TypeAttributes.ExplicitLayout wanneer u het type maakt. Pas in code het StructLayoutAttribute kenmerk met de LayoutKind.Explicit opsommingswaarde toe op het type om op te geven dat de verschuivingen waarop de velden beginnen expliciet worden opgegeven.
Note
U kunt de GetCustomAttributes methode niet gebruiken om te bepalen of de StructLayoutAttribute methode is toegepast op een type.
Als de huidige Type een samengesteld algemeen type vertegenwoordigt, is deze eigenschap van toepassing op de algemene typedefinitie van waaruit het type is samengesteld. Als de huidige Type bijvoorbeeld MyGenericType<int> (MyGenericType(Of Integer) in Visual Basic) vertegenwoordigt), wordt de waarde van deze eigenschap bepaald door MyGenericType<T>.
Als de huidige Type een typeparameter vertegenwoordigt in de definitie van een algemeen type of algemene methode, retourneert falsedeze eigenschap altijd .