다음을 통해 공유


BestFitMappingAttribute 클래스

유니코드 문자를 일치하는 가장 비슷한 ANSI 문자로 변환할지 여부를 제어합니다.

네임스페이스: System.Runtime.InteropServices
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Interface, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class BestFitMappingAttribute
    Inherits Attribute
‘사용 방법
Dim instance As BestFitMappingAttribute
[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 : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class BestFitMappingAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface, Inherited=false) 
ComVisibleAttribute(true) 
public final class BestFitMappingAttribute extends Attribute

설명

이 특성은 어셈블리, 인터페이스, 클래스 또는 구조체에 적용할 수 있습니다.

기본적으로 공용 언어 런타임에서는 Windows 98 또는 Windows Me에서 실행되는 관리되지 않는 메서드에 전달된 관리되는 모든 유니코드 문자를 ANSI 문자로 변환합니다. 가장 적합한 매핑을 사용하면 일치하는 문자가 없을 경우 Interop 마샬링이 가장 비슷하게 일치하는 문자를 선택할 수 있습니다. 예를 들어, 마샬러는 ANSI 문자가 적용되는 관리되지 않는 메서드에 대해 유니코드 저작권 문자를 'c'로 변환합니다.

경고

가장 적합한 표시가 없는 일부 문자는 매핑할 수 없는 것으로 간주됩니다. 매핑할 수 없는 문자는 주로 기본 '?'로 변환됩니다. ANSI 문자입니다. 특정 유니코드 문자가 백슬래시('\') 문자 등과 같이 경로를 변경할 수 있는 위험 문자로 변환됩니다.

BestFitMappingAttribute는 가장 적합한 매핑을 제어하기 위한 두 가지 매개 변수를 제공합니다. 첫 번째 매개 변수는 가장 적합한 매핑 기능을 켜거나 끄기 위해 사용합니다. 기본값은 true이며, 어셈블리, 인터페이스 및 클래스 수준에서 가장 적합한 매핑을 활성화합니다. 인터페이스나 클래스에 적용된 특성은 어셈블리 수준 특성을 재정의합니다. 플랫폼 호출에도 DllImportAttribute.BestFitMapping 필드를 사용하여 가장 적합한 매핑을 활성화하거나 비활성화할 수 있습니다. 플랫폼 호출 필드에 설정된 값은 모든 수준의 BestFitMappingAttribute를 재정의합니다.

두 번째 매개 변수를 사용하면 매핑할 수 없는 문자에 대한 예외 throw를 제어할 수 있습니다. ThrowOnUnmappableChar 필드의 기본값은 false이며, 런타임에 '?'로 변환되어야 하는 유니코드 문자가 나올 때마다 예외를 throw하지 않습니다. ANSI 문자입니다. 가장 적합한 매핑이 true일 경우에도 ThrowOnUnmappableChar 필드가 true이면 매핑할 수 없는 문자에서 예외를 발생시킵니다. 보안을 강화하려면 첫 번째 매개 변수를 false로, 두 번째 매개 변수를 true 설정합니다. 이렇게 두 매개 변수를 설정하면 가장 적합한 매핑 기능은 비활성화되지만 예외 throw 메커니즘을 보안 예방책으로 사용할 수 있습니다.

경고

ANSI 문자나 LPSTR 등의 요소로 이루어진 관리되는 배열을 관리되지 않는 안전한 배열에 전달할 때는 BestFitMappingAttribute에서 제공하는 기본값을 변경할 수 없습니다. 이 경우에는 가장 적합한 매핑이 항상 활성화되므로 예외가 throw될 수 없습니다. 이렇게 함께 사용하면 보안 모델이 손상될 수 있습니다.

예제

다음 예제에서는 가장 적합한 매핑을 비활성화하여 유니코드 문자를 '?'로 변환할 때 예외를 throw하는 방법을 보여 줍니다. ANSI 문자입니다. 이런 식으로 BestFitMappingAttribute 매개 변수를 설정하면 보안이 더욱 강화됩니다.

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

상속 계층 구조

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

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1에서 지원

참고 항목

참조

BestFitMappingAttribute 멤버
System.Runtime.InteropServices 네임스페이스
BestFitMapping