Freigeben über


BestFitMappingAttribute-Klasse

 

Veröffentlicht: Oktober 2016

Steuert, ob Unicode-Zeichen in möglichst passende ANSI-Zeichen konvertiert werden.

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

Vererbungshierarchie

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

Syntax

[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

Konstruktoren

Name Beschreibung
System_CAPS_pubmethod BestFitMappingAttribute(Boolean)

Initialisiert eine neue Instanz der der BestFitMappingAttribute auf den Wert der Klasse die BestFitMapping Eigenschaft.

Eigenschaften

Name Beschreibung
System_CAPS_pubproperty BestFitMapping

Ruft das Verhalten der Zuordnung mit ähnlichen Zeichen, bei der Konvertierung von Unicode-Zeichen in ANSI-Zeichen.

System_CAPS_pubproperty TypeId

Ruft bei Implementierung in einer abgeleiteten Klasse einen eindeutigen Bezeichner für dieses Attribute ab.(Geerbt von „Attribute“.)

Methoden

Name Beschreibung
System_CAPS_pubmethod Equals(Object)

Diese API unterstützt die Produkt Infrastruktur und sollte nicht direkt aus dem Code verwendet werden. Gibt einen Wert zurück, der angibt, ob diese Instanz gleich einem angegebenen Objekt ist.(Geerbt von „Attribute“.)

System_CAPS_pubmethod GetHashCode()

Gibt den Hashcode für diese Instanz zurück.(Geerbt von „Attribute“.)

System_CAPS_pubmethod GetType()

Ruft den Type der aktuellen Instanz ab.(Geerbt von „Object“.)

System_CAPS_pubmethod IsDefaultAttribute()

Gibt beim Überschreiben in einer abgeleiteten Klasse an, ob der Wert der Instanz der Standardwert für die abgeleitete Klasse ist.(Geerbt von „Attribute“.)

System_CAPS_pubmethod Match(Object)

Ruft beim Überschreiben in einer abgeleiteten Klasse gibt einen Wert, der angibt, ob diese Instanz gleich ein angegebenen Objekt ist.(Geerbt von „Attribute“.)

System_CAPS_pubmethod ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.(Geerbt von „Object“.)

Felder

Name Beschreibung
System_CAPS_pubfield ThrowOnUnmappableChar

Aktiviert bzw. deaktiviert das Auslösen einer Ausnahme bei einer nicht zuzuordnenden Unicode-Zeichen, die in ein ANSI konvertiert wird '?' Zeichen.

Explizite Schnittstellenimplementierungen

Name Beschreibung
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Ordnet eine Reihe von Namen einer entsprechenden Reihe von Dispatchbezeichnern zu.(Geerbt von „Attribute“.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Ruft die Typinformationen für ein Objekt ab, mit deren Hilfe die Typinformationen für eine Schnittstelle abgerufen werden können.(Geerbt von „Attribute“.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Ruft die Anzahl der Schnittstellen mit Typinformationen ab, die von einem Objekt bereitgestellt werden (0 oder 1).(Geerbt von „Attribute“.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Stellt den Zugriff auf von einem Objekt verfügbar gemachte Eigenschaften und Methoden bereit.(Geerbt von „Attribute“.)

Hinweise

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.

Warnung

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.

Warnung

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.

Beispiele

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.
};

Versionsinformationen

Universelle Windows-Plattform
Verfügbar seit 8
.NET Framework
Verfügbar seit 1.1
Portierbare Klassenbibliothek
Unterstützt in: portierbare .NET-Plattformen
Windows Phone
Verfügbar seit 8.1

Threadsicherheit

Alle öffentlichen statischen Member ( Shared in Visual Basic) dieses Typs sind threadsicher. Die Threadsicherheit für Instanzmember ist nicht garantiert.

Siehe auch

BestFitMapping
System.Runtime.InteropServices-Namespace
Interop Marshaling

Zurück zum Anfang