VariantWrapper Classe
Definição
Cuidado
VariantWrapper and support for marshalling to the VARIANT type may be unavailable in future releases.
Realiza marshaling de dados do tipo VT_VARIANT | VT_BYREF de código gerenciado para código não gerenciado.Marshals data of type VT_VARIANT | VT_BYREF from managed to unmanaged code. Essa classe não pode ser herdada.This class cannot be inherited.
public ref class VariantWrapper sealed
[System.Obsolete("VariantWrapper and support for marshalling to the VARIANT type may be unavailable in future releases.")]
public sealed class VariantWrapper
public sealed class VariantWrapper
[System.Serializable]
public sealed class VariantWrapper
[<System.Obsolete("VariantWrapper and support for marshalling to the VARIANT type may be unavailable in future releases.")>]
type VariantWrapper = class
type VariantWrapper = class
[<System.Serializable>]
type VariantWrapper = class
Public NotInheritable Class VariantWrapper
- Herança
-
VariantWrapper
- Atributos
Exemplos
O exemplo de código a seguir demonstra como usar a VariantWrapper classe para encapsular um Object que o Interop marshaler passa como VT_VARIANT | VT_BYREF .The following code example demonstrates how to use the VariantWrapper class to wrap an Object that the interop marshaler passes as VT_VARIANT | VT_BYREF.
// Create an instance of an unmanged COM object.
UnmanagedComClass UnmanagedComClassInstance = new UnmanagedComClass();
// Create a string to pass to the COM object.
string helloString = "Hello World!";
// Wrap the string with the VariantWrapper class.
object var = new System.Runtime.InteropServices.VariantWrapper(helloString);
// Pass the wrapped object.
UnmanagedComClassInstance.MethodWithStringRefParam(ref var);
' Create an instance of an unmanged COM object.
Dim UnmanagedComClassInstance As New UnmanagedComClass()
' Create a string to pass to the COM object.
Dim helloString As String = "Hello World!"
' Wrap the string with the VariantWrapper class.
Dim var As Object = New System.Runtime.InteropServices.VariantWrapper(helloString)
' Pass the wrapped object.
UnmanagedComClassInstance.MethodWithStringRefParam(var)
Comentários
A finalidade do VariantWrapper é adicionar um nível de indireção ao realizar o marshaling de um tipo gerenciado para o VARIANT tipo correspondente.The purpose of VariantWrapper is to add one level of indirection when marshaling a managed type to the corresponding VARIANT type.
Você pode usar essa classe para encapsular um Object que o Interop marshaler passa como VT_VARIANT | VT_BYREF .You can use this class to wrap an Object that the interop marshaler passes as VT_VARIANT | VT_BYREF. Nas versões 1,0 e 1,1 do .NET Framework, não era possível realizar marshaling de dados Variant do tipo VT_VARIANT | VT_BYREF para código não gerenciado.In versions 1.0 and 1.1 of the .NET Framework, it was not possible to marshal variant data of type VT_VARIANT | VT_BYREF to unmanaged code. O Interop marshaler passou uma variante do tipo gerenciado (por exemplo, VT_BSTR | VT_BYREF para String , ou VT_I4 | VT_BYREF para Int32 ), mas não VT_VARIANT | VT_BYREF .The interop marshaler passed a variant of the managed type (for example, VT_BSTR | VT_BYREF for String, or VT_I4 | VT_BYREF for Int32), but not VT_VARIANT | VT_BYREF.
Uma vantagem de usar VT_VARIANT | VT_BYREF tipos variantes é que o tipo de dados pode ser alterado durante uma chamada de método.One advantage of using VT_VARIANT | VT_BYREF variant types is that the type of data can be changed during a method call. Por exemplo, você pode passar um VT_VARIANT | VT_BYREF tipo Variant que contém um VT_BSTR e obter uma variante retornada que contém um VT_I4 após uma chamada de método.For example, you can pass a VT_VARIANT | VT_BYREF variant type that contains a VT_BSTR and get a variant returned that contains a VT_I4 after a method call. Como o marshaling interop do COM não tem como saber quando passar VT_BSTR | VT_BYREF e quando passar VT_VARIANT | VT_BYREF , que aponta para uma variante que contém um BSTR para parâmetros declarados como VARIANT * , você pode instruir o marshaler usando VariantWrapper .Because the COM interop marshaler has no way of knowing when to pass VT_BSTR | VT_BYREF and when to pass VT_VARIANT | VT_BYREF, which points to a variant that contains a BSTR for parameters declared as VARIANT *, you can instruct the marshaler by using VariantWrapper.
Observe que a ligação antecipada não tem suporte; Você pode usar VariantWrapper somente ao chamar InvokeMember ou com uma interface somente de expedição chamada em um modo de associação inicial.Note that early binding is not supported; you can use VariantWrapper only when calling InvokeMember or with a Dispatch-only interface called in an early bound fashion. Em C#, você também deve usar a ref palavra-chave para especificar a ByRef semântica para qualquer parâmetro do tipo VariantWrapper .In C#, you must also use the ref keyword to specify ByRef semantics for any parameter of type VariantWrapper. Em Visual Basic, a ByRef semântica é adicionada automaticamente para cada chamada de ligação tardia implícita.In Visual Basic, ByRef semantics are added automatically for every implicit late binding call. Observe também que VariantWrapper não há suporte para aninhar objetos e matrizes de VariantWrapper objetos.Also note that nesting VariantWrapper objects and arrays of VariantWrapper objects is not supported.
Construtores
| VariantWrapper(Object) |
Inicializa uma nova instância da classe VariantWrapper do parâmetro Object especificado.Initializes a new instance of the VariantWrapper class for the specified Object parameter. |
Propriedades
| WrappedObject |
Obtém o objeto encapsulado pelo objeto VariantWrapper.Gets the object wrapped by the VariantWrapper object. |
Métodos
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |