LCIDConversionAttribute Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Indica que a assinatura não gerida de um método espera um parâmetro de identificador local (LCID).
public ref class LCIDConversionAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
public sealed class LCIDConversionAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class LCIDConversionAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)>]
type LCIDConversionAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type LCIDConversionAttribute = class
inherit Attribute
Public NotInheritable Class LCIDConversionAttribute
Inherits Attribute
- Herança
- Atributos
Exemplos
O exemplo seguinte demonstra diferentes traduções de assinatura baseadas em diferentes valores fornecidos a LCIDConversionAttribute.
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Reflection;
#define LCID_INSTALLED 1
#define LCID_SUPPORTED 2
ref class LCIDAttrSample
{
public:
// Position of the LCID argument
[DllImport("KERNEL32.DLL",EntryPoint="IsValidLocale",SetLastError=true,CharSet=CharSet::Auto)]
[LCIDConversionAttribute(0)]
static bool IsValidLocale( int dwFlags ); // options
void CheckCurrentLCID()
{
MethodInfo^ mthIfo = this->GetType()->GetMethod( "IsValidLocale" );
Attribute^ attr = Attribute::GetCustomAttribute( mthIfo, LCIDConversionAttribute::typeid );
if ( attr != nullptr )
{
LCIDConversionAttribute^ lcidAttr = dynamic_cast<LCIDConversionAttribute^>(attr);
Console::WriteLine( "Position of the LCID argument in the unmanaged signature: {0}", lcidAttr->Value );
}
bool res = IsValidLocale( LCID_INSTALLED );
Console::WriteLine( "Result LCID_INSTALLED {0}", res );
res = IsValidLocale( LCID_SUPPORTED );
Console::WriteLine( "Result LCID_SUPPORTED {0}", res );
}
};
int main()
{
LCIDAttrSample^ smpl = gcnew LCIDAttrSample;
smpl->CheckCurrentLCID();
}
using System;
using System.Runtime.InteropServices;
using System.Reflection;
class LCIDAttrSample
{
private const int LCID_INSTALLED = 1;
private const int LCID_SUPPORTED = 2;
[DllImport("KERNEL32.DLL", EntryPoint="IsValidLocale", SetLastError = true, CharSet = CharSet.Auto)]
[LCIDConversionAttribute(0)] // Position of the LCID argument
public static extern bool IsValidLocale(
uint dwFlags // options
);
public void CheckCurrentLCID()
{
MethodInfo mthIfo = this.GetType().GetMethod("IsValidLocale");
Attribute attr = Attribute.GetCustomAttribute(mthIfo,typeof(LCIDConversionAttribute));
if( attr != null)
{
LCIDConversionAttribute lcidAttr = (LCIDConversionAttribute)attr;
Console.WriteLine("Position of the LCID argument in the unmanaged signature: " + lcidAttr.Value.ToString());
}
bool res = IsValidLocale(LCID_INSTALLED);
Console.WriteLine("Result LCID_INSTALLED " + res.ToString());
res = IsValidLocale(LCID_SUPPORTED);
Console.WriteLine("Result LCID_SUPPORTED " + res.ToString());
}
static void Main(string[] args)
{
LCIDAttrSample smpl = new LCIDAttrSample();
smpl.CheckCurrentLCID();
}
}
Imports System.Runtime.InteropServices
Imports System.Reflection
Class LCIDAttrSampler
Const LCID_INSTALLED As Integer = 1
Const LCID_SUPPORTED As Integer = 2
<DllImport("KERNEL32.DLL", EntryPoint:="IsValidLocale", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
CallingConvention:=CallingConvention.StdCall), _
LCIDConversionAttribute(0)> _
Public Shared Function IsValidLocale(ByVal dwFlags As Integer) As Boolean
End Function
Public Sub CheckCurrentLCID()
Dim mthIfo As MethodInfo = Me.GetType().GetMethod("IsValidLocale")
Dim attr As Attribute = Attribute.GetCustomAttribute(mthIfo, GetType(LCIDConversionAttribute))
If Not(attr Is Nothing) Then
Dim lcidAttr As LCIDConversionAttribute = CType(attr, LCIDConversionAttribute)
Console.WriteLine("Position of the LCID argument in the unmanaged signature: " + lcidAttr.Value.ToString())
End If
Dim res As Boolean = IsValidLocale(LCID_INSTALLED)
Console.WriteLine("Result LCID_INSTALLED " + res.ToString())
res = IsValidLocale(LCID_SUPPORTED)
Console.WriteLine("Result LCID_SUPPORTED " + res.ToString())
End Sub
Public Shared Sub Main()
Dim smpl As LCIDAttrSampler = New LCIDAttrSampler()
smpl.CheckCurrentLCID()
End Sub
End Class
Observações
Pode aplicar esta característica a métodos.
Este atributo indica que o marshaler deve esperar que um LCID seja passado após o argumento do método designado. Quando são feitas chamadas de código gerido para código não gerido, o marshaler fornece automaticamente o argumento LCID.
Construtores
| Name | Description |
|---|---|
| LCIDConversionAttribute(Int32) |
Inicializa uma nova instância da |
Propriedades
| Name | Description |
|---|---|
| TypeId |
Quando implementado numa classe derivada, obtém um identificador único para esta Attribute. (Herdado de Attribute) |
| Value |
Obtém a posição do argumento do LCID na assinatura não gerida. |
Métodos
| Name | Description |
|---|---|
| Equals(Object) |
Devolve um valor que indica se esta instância é igual a um objeto especificado. (Herdado de Attribute) |
| GetHashCode() |
Devolve o código de hash para esta instância. (Herdado de Attribute) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| IsDefaultAttribute() |
Quando sobrescrito numa classe derivada, indica se o valor desta instância é o valor padrão para a classe derivada. (Herdado de Attribute) |
| Match(Object) |
Quando sobrescrito numa classe derivada, devolve um valor que indica se esta instância é igual a um objeto especificado. (Herdado de Attribute) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |
Implementações de Interface Explícita
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de despacho. (Herdado de Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera a informação de tipo de um objeto, que pode ser usada para obter a informação de tipo para uma interface. (Herdado de Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera o número de interfaces de informações de tipo que um objeto fornece (0 ou 1). (Herdado de Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Proporciona acesso a propriedades e métodos expostos por um objeto. (Herdado de Attribute) |