BestFitMappingAttribute クラス

定義

Unicode 文字を最も近い一致する ANSI 文字に変換するかどうかを制御します。

public ref class BestFitMappingAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)]
public sealed class BestFitMappingAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class BestFitMappingAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)>]
type BestFitMappingAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type BestFitMappingAttribute = class
    inherit Attribute
Public NotInheritable Class BestFitMappingAttribute
Inherits Attribute
継承
BestFitMappingAttribute
属性

次の例では、最適なマッピングを無効にし、Unicode 文字から '?' への変換時に例外をスローする方法を示します。ANSI 文字。 この方法でパラメーター BestFitMappingAttribute 設定すると、セキュリティが強化されます。

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

注釈

この属性は、アセンブリ、インターフェイス、クラス、または構造体に適用できます。

Caution

一部の文字には最適な表現がありません。これらの文字は、マップ不可と呼ばれます。 通常、マップできない文字は既定の '?' に変換されます。ANSI 文字。 特定の Unicode 文字は、バックスラッシュ '\' 文字などの危険な文字に変換され、パスが誤って変更される可能性があります。

BestFitMappingAttribute には、最適なマッピングの側面を制御するための 2 つのパラメーターが用意されています。 最初のパラメーターを使用して、最適なマッピングのオンとオフを切り替えます。 既定値は true であり、アセンブリ、インターフェイス、およびクラス レベルで最適なマッピングが可能になります。 インターフェイスまたはクラスに適用される属性は、アセンブリ レベルの属性をオーバーライドします。 同様に、 DllImportAttribute.BestFitMapping フィールドを使用して、プラットフォーム呼び出しの最適なマッピングを有効または無効にすることができます。 プラットフォーム呼び出しフィールドによって設定された値は、すべてのレベルの BestFitMappingAttributeをオーバーライドします。

2 番目のパラメーターを使用して、適用できない文字に対する例外のスローを制御できます。 ThrowOnUnmappableChar フィールドの既定値は false です。これは、ランタイムが '?' に変換する必要がある Unicode 文字を検出するたびに例外をスローすることを無効にします。ANSI 文字。 最適なマッピングが trueされている場合でも、 ThrowOnUnmappableChar フィールドが trueされると、マップできない文字によって例外が生成されます。 セキュリティを強化するために、最初のパラメーターを false に切り替え、2 番目のパラメーターを trueに切り替えることができます。 このパラメーター設定の組み合わせにより、最適なマッピングがオフになりますが、安全上の予防措置として例外スローメカニズムが有効になります。

Caution

要素が ANSI 文字または LPSTR であるマネージド配列をアンマネージド セーフ配列に渡す場合、 BestFitMappingAttribute によって提供される既定値を変更することはできません。 最適なマッピングは常に有効になっており、例外はスローされません。 この組み合わせによってセキュリティ モデルが損なわれる可能性があることに注意してください。

コンストラクター

名前 説明
BestFitMappingAttribute(Boolean)

BestFitMapping プロパティの値に設定されたBestFitMappingAttribute クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
ThrowOnUnmappableChar

ANSI '?' 文字に変換される、適用できない Unicode 文字に対する例外のスローを有効または無効にします。

プロパティ

名前 説明
BestFitMapping

Unicode 文字を ANSI 文字に変換するときの最適なマッピング動作を取得します。

TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされた場合、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

名前 説明
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください