TypeConverterAttribute 클래스

정의

이 특성이 바인딩되는 개체에 대한 변환기로 사용할 형식을 지정합니다.

public ref class TypeConverterAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class TypeConverterAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type TypeConverterAttribute = class
    inherit Attribute
Public NotInheritable Class TypeConverterAttribute
Inherits Attribute
상속
TypeConverterAttribute
특성

예제

다음 예제에서는 라는 MyClassConverter형식 변환기를 사용 하 여 선언 MyClass 합니다. 이 예제에서는 가 MyClassConverter 다른 곳에서 구현되었다고 가정합니다. 변환기(MyClassConverter)를 구현하는 클래스는 클래스에서 TypeConverter 상속되어야 합니다.

[TypeConverter(Class1::MyClassConverter::typeid)]
ref class MyClass{
   // Insert code here.
};
[TypeConverter(typeof(MyClassConverter))]
 public class MyClass {
    // Insert code here.
 }
<TypeConverter(GetType(MyClassConverter))> _
Public Class ClassA
    ' Insert code here.
End Class

다음 예제에서는 인스턴스 MyClass를 만듭니다. 그런 다음 클래스의 특성을 가져오고 에서 사용하는 MyClass형식 변환기의 이름을 출력합니다.

int main()
{
   // Creates a new instance of MyClass.
   Class1::MyClass^ myNewClass = gcnew Class1::MyClass;

   // Gets the attributes for the instance.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewClass );

   /* Prints the name of the type converter by retrieving the 
        * TypeConverterAttribute from the AttributeCollection. */
   TypeConverterAttribute^ myAttribute = dynamic_cast<TypeConverterAttribute^>(attributes[ TypeConverterAttribute::typeid ]);
   Console::WriteLine( "The type converter for this class is: {0}", myAttribute->ConverterTypeName );
   return 0;
}
public static int Main() {
    // Creates a new instance of MyClass.
    MyClass myNewClass = new MyClass();
 
    // Gets the attributes for the instance.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewClass);
 
    /* Prints the name of the type converter by retrieving the 
     * TypeConverterAttribute from the AttributeCollection. */
    TypeConverterAttribute myAttribute = 
        (TypeConverterAttribute)attributes[typeof(TypeConverterAttribute)];
    
    Console.WriteLine("The type conveter for this class is: " + 
        myAttribute.ConverterTypeName);
 
    return 0;
 }
Public Shared Function Main() As Integer
    ' Creates a new instance of ClassA.
    Dim myNewClass As New ClassA()
    
    ' Gets the attributes for the instance.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewClass)
    
    ' Prints the name of the type converter by retrieving the
    ' TypeConverterAttribute from the AttributeCollection. 
    Dim myAttribute As TypeConverterAttribute = _
        CType(attributes(GetType(TypeConverterAttribute)), TypeConverterAttribute)
    
    Console.WriteLine(("The type conveter for this class is: " _
        + myAttribute.ConverterTypeName))
    Return 0
End Function 'Main

설명

변환에 사용하는 클래스는 에서 TypeConverter상속되어야 합니다. 사용 된 ConverterTypeName 속성을 이 특성이 바인딩된 개체에 대 한 데이터 변환을 제공 하는 클래스의 이름을 가져옵니다.

특성에 대한 자세한 내용은 특성을 참조하세요. 형식 변환기에 대 한 자세한 내용은 참조는 TypeConverter 기본 클래스 및 방법: 형식 변환기를 구현합니다.

XAML에 대한 형식 변환 동작을 제공하는 사용자 지정 클래스에 형식 변환기를 설정하려면 특성을 형식에 TypeConverterAttribute 적용합니다. 특성의 인수는 형식 변환기 구현을 참조합니다. 형식 변환기는 XAML 태그의 특성 또는 초기화 텍스트에 사용되는 문자열의 값을 수락하고 해당 문자열을 원하는 대상 형식으로 변환할 수 있어야 합니다. 자세한 내용은 TypeConverters 및 XAML을 참조하세요.

형식의 모든 값에 적용하는 대신 특정 속성에서 XAML에 대한 형식 변환기 동작을 설정할 수도 있습니다. 이 경우 TypeConverterAttribute를 속성 정의(특정 getset 정의가 아닌 외부 정의)에 적용합니다.

XAML 사용을 지원하는 get 메서드 접근자에 TypeConverterAttribute을 적용하여 사용자 지정 연결 가능 멤버의 XAML 사용에 대한 형식 변환기 동작을 할당할 수 있습니다. 자세한 내용은 연결된 속성 개요를 참조하세요.

개체 런타임에서 추가 상태가 필요한 복잡한 XAML serialization 사례의 경우 형식 변환기 외에도 값 serializer를 정의하고 사용자 지정 형식 또는 사용자 지정 멤버에 대한 두 지원 클래스를 모두 특성으로 지정합니다. 자세한 내용은 ValueSerializer를 참조하세요.

생성자

TypeConverterAttribute()

기본 형식 변환기를 사용하여 TypeConverterAttribute 클래스의 새 인스턴스를 초기화합니다. 기본 형식 변환기는 빈 문자열("")입니다.

TypeConverterAttribute(String)

지정된 형식 이름을 이 특성이 바인딩되는 개체의 데이터 변환기로 사용하여 TypeConverterAttribute 클래스의 새 인스턴스를 초기화합니다.

TypeConverterAttribute(Type)

지정된 형식을 이 특성이 바인딩되는 개체의 데이터 변환기로 사용하여 TypeConverterAttribute 클래스의 새 인스턴스를 초기화합니다.

필드

Default

이 특성이 바인딩되는 개체의 변환기로 사용할 형식을 지정합니다.

속성

ConverterTypeName

이 특성이 바인딩되는 개체의 변환기로 사용할 Type의 정규화된 형식 이름을 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

주어진 개체의 값이 현재 TypeConverterAttribute와 같은지 여부를 반환합니다.

GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

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)

적용 대상

추가 정보