次の方法で共有


TypeConverterAttribute クラス

この属性が関連付けられているオブジェクトのコンバータとして使用する型を指定します。このクラスは継承できません。

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)

構文

'宣言
<AttributeUsageAttribute(AttributeTargets.All)> _
Public NotInheritable Class TypeConverterAttribute
    Inherits Attribute
'使用
Dim instance As TypeConverterAttribute
[AttributeUsageAttribute(AttributeTargets.All)] 
public sealed class TypeConverterAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All)] 
public ref class TypeConverterAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All) */ 
public final class TypeConverterAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All) 
public final class TypeConverterAttribute extends Attribute

解説

変換に使用するクラスは、TypeConverter から継承する必要があります。ConverterTypeName プロパティを使用して、この属性が関連付けられているオブジェクトのデータ変換を実現するクラスの名前を取得します。

属性の詳細については、「属性の概要」と「属性を使用したメタデータの拡張」を参照してください。型コンバータの詳細については、TypeConverter 基本クラスのトピックおよび「方法 : 型コンバータを実装する」を参照してください。

使用例

MyClass に対して、MyClassConverter という名前の型コンバータを使用するように指示する例を次に示します。この例は、MyClassConverter が別の場所で実装されていることを前提にしています。コンバータ (MyClassConverter) を実装するクラスは、TypeConverter クラスから継承する必要があります。

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

MyClass のインスタンスを作成する例を次に示します。そのクラスの属性を取得し、MyClass で使用する型コンバータの名前を出力します。

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
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;
 }
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 void main(String[] args)
{
    // 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.get_Item( TypeConverterAttribute.class.ToType())));
    Console.WriteLine(("The type conveter for this class is: " 
        + myAttribute.get_ConverterTypeName()));
   } //main 

継承階層

System.Object
   System.Attribute
    System.ComponentModel.TypeConverterAttribute

スレッド セーフ

この型の 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、1.0

参照

関連項目

TypeConverterAttribute メンバ
System.ComponentModel 名前空間
TypeConverter クラス