Clase LCIDConversionAttribute
Publicado: octubre de 2016
Indica que la firma no administrada de un método espera un parámetro de configuración regional (LCID) de identificador.
Espacio de nombres: System.Runtime.InteropServices
Ensamblado: mscorlib (en mscorlib.dll)
Jerarquía de herencia
System.Object
System.Attribute
System.Runtime.InteropServices.LCIDConversionAttribute
Sintaxis
[AttributeUsageAttribute(AttributeTargets.Method, Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class LCIDConversionAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class LCIDConversionAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Method, Inherited = false)>]
[<ComVisibleAttribute(true)>]
type LCIDConversionAttribute =
class
inherit Attribute
end
<AttributeUsageAttribute(AttributeTargets.Method, Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class LCIDConversionAttribute
Inherits Attribute
Constructores
Nombre | Descripción | |
---|---|---|
![]() |
LCIDConversionAttribute(Int32) | Inicializa una nueva instancia de la LCIDConversionAttribute clase con la posición del LCID en la firma no administrada. |
Propiedades
Nombre | Descripción | |
---|---|---|
![]() |
TypeId | Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.(Heredado de Attribute). |
![]() |
Value | Obtiene la posición del argumento LCID en la firma no administrada. |
Métodos
Nombre | Descripción | |
---|---|---|
![]() |
Equals(Object) | Esta API admite la infraestructura producto y no está diseñada para usarse directamente desde el código. Devuelve un valor que indica si esta instancia es igual que un objeto especificado.(Heredado de Attribute). |
![]() |
GetHashCode() | Devuelve el código hash de esta instancia.(Heredado de Attribute). |
![]() |
GetType() | Obtiene el Type de la instancia actual.(Heredado de Object). |
![]() |
IsDefaultAttribute() | Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.(Heredado de Attribute). |
![]() |
Match(Object) | Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.(Heredado de Attribute). |
![]() |
ToString() | Devuelve una cadena que representa el objeto actual.(Heredado de Object). |
Implementaciones de interfaz explícitas
Nombre | Descripción | |
---|---|---|
![]() ![]() |
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.(Heredado de Attribute). |
![]() ![]() |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.(Heredado de Attribute). |
![]() ![]() |
_Attribute.GetTypeInfoCount(UInt32) | Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).(Heredado de Attribute). |
![]() ![]() |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | Proporciona acceso a las propiedades y los métodos expuestos por un objeto.(Heredado de Attribute). |
Comentarios
Este atributo se puede aplicar a métodos.
Este atributo indica que el contador de referencias debe esperar un LCID pasarse después del argumento de método designado. Cuando se realizan llamadas desde código administrado a no administrado, el contador de referencias proporciona el argumento LCID automáticamente.
Ejemplos
El ejemplo siguiente muestra distintas conversiones de firma basadas en diferentes valores proporcionados para LCIDConversionAttribute.
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
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
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();
}
Información de versión
.NET Framework
Disponible desde 1.1
Seguridad para subprocesos
Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.
Ver también
Espacio de nombres System.Runtime.InteropServices
Volver al principio