Compartilhar via


Método Marshal.OffsetOf (Type, String)

 

Retorna o deslocamento de campo do formulário não gerenciado da classe gerenciada.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (em mscorlib.dll)

Sintaxe

public static IntPtr OffsetOf(
    Type t,
    string fieldName
)
public:
static IntPtr OffsetOf(
    Type^ t,
    String^ fieldName
)
static member OffsetOf : 
        t:Type *
        fieldName:string -> nativeint
Public Shared Function OffsetOf (
    t As Type,
    fieldName As String
) As IntPtr

Parâmetros

  • t
    Type: System.Type

    Um tipo de valor ou tipo de referência formatada que especifica a classe gerenciada. Você deve aplicar o StructLayoutAttribute à classe.

Valor Retornado

Type: System.IntPtr

O deslocamento, em bytes, para o parâmetro fieldName dentro da classe especificada que é declarado pela invocação de plataforma.

Exceções

Exception Condition
ArgumentException

A classe não pode ser exportada, visto que uma estrutura ou o campo é confidencial. A partir do .NET Framework versão 2.0, o campo pode ser privado.

ArgumentNullException

O parâmetro t é null.

Comentários

OffsetOf provides the offset in terms of the unmanaged structure layout, which does not necessarily correspond to the offset of the managed structure layout. Marshaling the structure can transform the layout and alter the offset. The t parameter can be a value type or a formatted reference type (with either a sequential or explicit layout). You can obtain the size of the entire layout by using the Marshal.SizeOf method. For additional information, see Default Marshaling for Value Types.

Dica

Beginning with the .NET Framework version 2.0, M:System.Runtime.InteropServices.Marshal.OffsetOf(System.Type,System.String) may expose private fields.

Informações de Versão

Plataforma Universal do Windows
Disponível desde 8
.NET Framework
Disponível desde 1.1
Biblioteca de Classes Portátil
Com suporte no: plataformas portáteis do .NET
Windows Phone
Disponível desde 8.1

Confira Também

SizeOf
OffsetOf Sobrecarga
Classe Marshal
Namespace System.Runtime.InteropServices

Retornar ao início