Compartir a través de


Clase BestFitMappingAttribute

 

Publicado: octubre de 2016

Controla si los caracteres Unicode se convierten en los caracteres ANSI coincidentes más cercanos.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Jerarquía de herencia

System.Object
  System.Attribute
    System.Runtime.InteropServices.BestFitMappingAttribute

Sintaxis

[AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, 
    Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class BestFitMappingAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly | AttributeTargets::Class | AttributeTargets::Struct | AttributeTargets::Interface, 
    Inherited = false)]
[ComVisibleAttribute(true)]
public ref class BestFitMappingAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface,
    Inherited = false)>]
[<ComVisibleAttribute(true)>]
type BestFitMappingAttribute = 
    class
        inherit Attribute
    end
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Interface,
    Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class BestFitMappingAttribute
    Inherits Attribute

Constructores

Nombre Descripción
System_CAPS_pubmethod BestFitMappingAttribute(Boolean)

Inicializa una nueva instancia de la BestFitMappingAttribute clase establecido en el valor de la BestFitMapping propiedad.

Propiedades

Nombre Descripción
System_CAPS_pubproperty BestFitMapping

Obtiene el comportamiento de asignación con ajuste perfecto al convertir caracteres Unicode en caracteres ANSI.

System_CAPS_pubproperty TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.(Heredado de Attribute).

Métodos

Nombre Descripción
System_CAPS_pubmethod 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).

System_CAPS_pubmethod GetHashCode()

Devuelve el código hash de esta instancia.(Heredado de Attribute).

System_CAPS_pubmethod GetType()

Obtiene el Type de la instancia actual.(Heredado de Object).

System_CAPS_pubmethod 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).

System_CAPS_pubmethod 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).

System_CAPS_pubmethod ToString()

Devuelve una cadena que representa el objeto actual.(Heredado de Object).

Campos

Nombre Descripción
System_CAPS_pubfield ThrowOnUnmappableChar

Habilita o deshabilita el inicio de una excepción cuando un carácter Unicode que se convierte en un carácter '?' caracteres.

Implementaciones de interfaz explícitas

Nombre Descripción
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _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).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _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

You can apply this attribute to an assembly, interface, class, or structure.

By default, the common language runtime converts to ANSI characters any managed Unicode characters passed to an unmanaged method executing on Windows 98 or Windows Me. Best-fit mapping enables the interop marshaler to select a close-matching character when no exact match exists. For example, the marshaler converts the Unicode copyright character to 'c' for unmanaged methods that accept ANSI characters.

Advertencia

Some characters lack a best-fit representation; these characters are called unmappable. Unmappable characters are usually converted to the default '?' ANSI character. Certain Unicode characters are converted to dangerous characters, such as the backslash '\' character, which can inadvertently change a path.

BestFitMappingAttribute provides two parameters to control aspects of best-fit mapping. You use the first parameter to toggle best-fit mapping on and off. The default value is true, which enables best-fit mapping on the assembly, interface, and class levels. An attribute applied to an interface or class overrides an assembly-level attribute. You can likewise enable or disable best-fit mapping for platform invoke calls by using the DllImportAttribute.BestFitMapping field. A value set by the platform invoke field overrides all levels of BestFitMappingAttribute.

You can use the second parameter to control throwing an exception on unmappable characters. The default value for the F:System.Runtime.InteropServices.BestFitMappingAttribute.ThrowOnUnmappableChar field is false, which disables throwing an exception each time the runtime encounters a Unicode character that has to be converted to the '?' ANSI character. Even if best-fit mapping is true, unmappable characters generate an exception when the F:System.Runtime.InteropServices.BestFitMappingAttribute.ThrowOnUnmappableChar field is true. To tighten security, you can toggle the first parameter to false and the second parameter to true. This combination of parameter settings turns best-fit mapping off, but enables the exception-throwing mechanism as a safety precaution.

Advertencia

You cannot change the default values provided by T:System.Runtime.InteropServices.BestFitMappingAttribute when passing a managed array whose elements are ANSI Chars or LPSTRs to an unmanaged safe array. Best-fit mapping is always enabled and no exception can be thrown. Be aware that this combination can compromise your security model.

Ejemplos

The following example shows how to disable best fit mapping and to throw an exception on the conversion of Unicode characters to the '?' ANSI character. Setting T:System.Runtime.InteropServices.BestFitMappingAttribute parameters in this manner provides an added measure of security.

[BestFitMapping(false, ThrowOnUnmappableChar = true)]
interface IMyInterface1
{
     //Insert code here.
}
<BestFitMapping(False, ThrowOnUnmappableChar := True)> _
Interface IMyInterface1
     'Insert code here.
End Interface
[BestFitMapping(false, ThrowOnUnmappableChar = true)]
interface class IMyInterface1
{
     //Insert code here.
};

Información de versión

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Windows Phone
Disponible desde 8.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

BestFitMapping
Espacio de nombres System.Runtime.InteropServices
Interop Marshaling

Volver al principio