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

備註

您可以將此屬性套用至元件、介面、類別或結構。

警告

某些字元缺少最適合的標記法;這些字元稱為無法套用。 無法套用的字元通常會轉換成預設 '?'ANSI 字元。 某些 Unicode 字元會轉換成危險字元,例如反斜線 '\' 字元,這可能會不小心變更路徑。

BestFitMappingAttribute 提供兩個參數來控制最適合對應的層面。 您可以使用第一個參數來切換開啟和關閉最適合的對應。 預設值為 true ,可在元件、介面和類別層級上啟用最適合的對應。 套用至介面或類別的屬性會覆寫元件層級屬性。 您也可以使用 DllImportAttribute.BestFitMapping 欄位來啟用或停用平台叫用呼叫的最佳對應。 平台叫用欄位所設定的值會覆寫 所有層級。 BestFitMappingAttribute

您可以使用第二個參數來控制在無法套用的字元上擲回例外狀況。 欄位的 ThrowOnUnmappableChar 預設值為 false ,這會停用每次執行時間遇到必須轉換成 '?' 的 Unicode 字元時擲回例外狀況ANSI 字元。 即使最適合的對應為 ,當欄位為 truetrue 時,無法套用的 ThrowOnUnmappableChar 字元仍會產生例外狀況。 若要加強安全性,您可以將第一個參數切換為 false ,並將第二個參數切換為 true 。 這個參數設定組合會關閉最適合的對應,但會啟用例外狀況擲回機制作為安全預防措施。

警告

將元素為 ANSI Chars 或 LPSTR 的 Managed 陣列傳遞至 Unmanaged 安全陣列時,您無法將 所提供的 BestFitMappingAttribute 預設值變更為 。 一律會啟用最適合的對應,而且無法擲回任何例外狀況。 請注意,此組合可能會危害您的安全性模型。

建構函式

BestFitMappingAttribute(Boolean)

初始化 BestFitMappingAttribute 類別的新執行個體,這個執行個體設定為 BestFitMapping 屬性的值。

欄位

ThrowOnUnmappableChar

在無法對應的 Unicode 字元轉換為 ANSI '?' 字元時,啟用或停用擲回例外狀況。

屬性

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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱