InstanceDescriptor クラス
アセンブリ: System (system.dll 内)


InstanceDescriptor は、オブジェクトのインスタンスを記述する情報を格納できます。この情報を使用して、オブジェクトのインスタンスを作成できます。
カスタム シリアライザの種類によっては、シリアル化できるオブジェクトを表すために InstanceDescriptor を使用することがあります。TypeDescriptor のいくつかのメソッドは、InstanceDescriptor を使用して、オブジェクトを表現またはインスタンス化します。
InstanceDescriptor は次のメンバを提供します。
![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |

インスタンス記述子を使用してコード生成に関与する型コンバータを使用するコード例を次に示します。
Imports System Imports System.ComponentModel Imports System.ComponentModel.Design.Serialization Imports System.Drawing Imports System.Globalization Imports System.Reflection Namespace Microsoft.Samples.InstanceDescriptorSample ' This sample shows how to support code generation for a custom type ' of object using a type converter and InstanceDescriptor objects. ' ' To use this code, copy it to a file and add the file to a project. ' Then add a component to the project and declare a Triangle field and ' a public property with accessors for the Triangle field on the component. ' ' The Triangle property will be persisted using code generation. <TypeConverter(GetType(Triangle.TriangleConverter))> _ Public Class Triangle ' Triangle members. Private P1 As Point Private P2 As Point Private P3 As Point Public Property Point1() As Point Get Return P1 End Get Set(ByVal Value As Point) P1 = Value End Set End Property Public Property Point2() As Point Get Return P2 End Get Set(ByVal Value As Point) P2 = Value End Set End Property Public Property Point3() As Point Get Return P3 End Get Set(ByVal Value As Point) P3 = Value End Set End Property Public Sub New(ByVal point1 As Point, ByVal point2 As Point, ByVal point3 As Point) P1 = point1 P2 = point2 P3 = point3 End Sub 'New ' A TypeConverter for the Triangle object. Note that you can make it internal, ' private, or any scope you want and the designers will still be able to use ' it through the TypeDescriptor object. This type converter provides the ' capability to convert to an InstanceDescriptor. This object can be used by ' the .NET Framework to generate source code that creates an instance of a ' Triangle object. Friend Class TriangleConverter Inherits TypeConverter ' This method overrides CanConvertTo from TypeConverter. This is called when someone ' wants to convert an instance of Triangle to another type. Here, ' only coversition to an InstanceDescriptor is supported. Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean If destinationType Is GetType(InstanceDescriptor) Then Return True End If ' Always call the base to see if it can perform the conversion. Return MyBase.CanConvertTo(context, destinationType) End Function ' This code performs the actual conversion from a Triangle to an InstanceDescriptor. Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object If destinationType Is GetType(InstanceDescriptor) Then Dim ci As ConstructorInfo = GetType(Triangle).GetConstructor(New Type() {GetType(Point), GetType(Point), GetType(Point)}) Dim t As Triangle = CType(value, Triangle) Return New InstanceDescriptor(ci, New Object() {t.Point1, t.Point2, t.Point3}) End If ' Always call base, even if you can't convert. Return MyBase.ConvertTo(context, culture, value, destinationType) End Function End Class End Class Public Class TestComponent Inherits System.ComponentModel.Component Private myTriangleProp As Triangle Public Sub New() myTriangleProp = New Triangle(New Point(5, 5), _ New Point(10, 10), New Point(1, 8)) End Sub Public Property MyTriangle() As Triangle Get Return myTriangleProp End Get Set(ByVal Value As Triangle) myTriangleProp = Value End Set End Property End Class End Namespace
namespace Microsoft.Samples.InstanceDescriptorSample { using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Drawing; using System.Globalization; using System.Reflection; // This sample shows how to support code generation for a custom type // of object using a type converter and InstanceDescriptor objects. // To use this code, copy it to a file and add the file to a project. // Then add a component to the project and declare a Triangle field and // a public property with accessors for the Triangle field on the component. // The Triangle property will be persisted using code generation. [TypeConverter(typeof(Triangle.TriangleConverter))] public class Triangle { // Triangle members. Point P1; Point P2; Point P3; public Point Point1 { get { return P1; } set { P1 = value; } } public Point Point2 { get { return P2; } set { P2 = value; } } public Point Point3 { get { return P3; } set { P3 = value; } } public Triangle(Point point1,Point point2,Point point3) { P1 = point1; P2 = point2; P3 = point3; } // A TypeConverter for the Triangle object. Note that you can make it internal, // private, or any scope you want and the designers will still be able to use // it through the TypeDescriptor object. This type converter provides the // capability to convert to an InstanceDescriptor. This object can be used by // the .NET Framework to generate source code that creates an instance of a // Triangle object. internal class TriangleConverter : TypeConverter { // This method overrides CanConvertTo from TypeConverter. This is called when someone // wants to convert an instance of Triangle to another type. Here, // only conversion to an InstanceDescriptor is supported. public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } // Always call the base to see if it can perform the conversion. return base.CanConvertTo(context, destinationType); } // This code performs the actual conversion from a Triangle to an InstanceDescriptor. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(Triangle).GetConstructor(new Type[]{typeof(Point), typeof(Point),typeof(Point)}); Triangle t = (Triangle) value; return new InstanceDescriptor(ci,new object[]{t.Point1,t.Point2,t.Point3}); } // Always call base, even if you can't convert. return base.ConvertTo(context, culture, value, destinationType); } } } public class TestComponent : System.ComponentModel.Component { Triangle myTriangle; public TestComponent() { myTriangle = new Triangle( new Point(5,5), new Point(10,10), new Point(1,8) ); } public Triangle MyTriangle { get { return myTriangle; } set { myTriangle = value; } } } }
#using <system.dll> #using <system.drawing.dll> using namespace System; using namespace System::ComponentModel; using namespace System::ComponentModel::Design::Serialization; using namespace System::Drawing; using namespace System::Globalization; using namespace System::Collections; using namespace System::Reflection; /* This sample shows how to support code generation for a custom type of object using a type converter and InstanceDescriptor objects. To use this code, copy it to a file and add the file to a project. Then add a component to the project and declare a Triangle field and a public property with accessors for the Triangle field on the component. The Triangle property will be persisted using code generation. */ ref class TriangleConverter; [TypeConverter(TriangleConverter::typeid)] public ref class Triangle { private: // Triangle members Point P1; Point P2; Point P3; public: property Point Point1 { Point get() { return P1; } void set( Point value ) { P1 = value; } } property Point Point2 { Point get() { return P2; } void set( Point value ) { P2 = value; } } property Point Point3 { Point get() { return P3; } void set( Point value ) { P3 = value; } } Triangle( Point point1, Point point2, Point point3 ) { P1 = point1; P2 = point2; P3 = point3; } /* A TypeConverter for the Triangle object. Note that you can make it internal, private, or any scope you want and the designers will still be able to use it through the TypeDescriptor object. This type converter provides the capability to convert to an InstanceDescriptor. This object can be used by the .NET Framework to generate source code that creates an instance of a Triangle object. */ [System::Security::Permissions::PermissionSet(System::Security:: Permissions::SecurityAction::Demand, Name = "FullTrust")] ref class TriangleConverter: public TypeConverter { public: /* This method overrides CanConvertTo from TypeConverter. This is called when someone wants to convert an instance of Triangle to another type. Here, only conversion to an InstanceDescriptor is supported. */ virtual bool CanConvertTo( ITypeDescriptorContext^ context, Type^ destinationType ) override { if ( destinationType == InstanceDescriptor::typeid ) { return true; } // Always call the base to see if it can perform the conversion. return TypeConverter::CanConvertTo( context, destinationType ); } /* This code performs the actual conversion from a Triangle to an InstanceDescriptor. */ virtual Object^ ConvertTo( ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value, Type^ destinationType ) override { if ( destinationType == InstanceDescriptor::typeid ) { array<Type^>^type1 = {Point::typeid,Point::typeid,Point::typeid}; ConstructorInfo^ ci = Triangle::typeid->GetConstructor( type1 ); Triangle^ t = safe_cast<Triangle^>(value); array<Object^>^obj1 = {t->Point1,t->Point2,t->Point3}; return gcnew InstanceDescriptor( ci,safe_cast<ICollection^>(obj1) ); } // Always call base, even if you can't convert. return TypeConverter::ConvertTo( context, culture, value, destinationType ); } }; }; public ref class TestComponent: public System::ComponentModel::Component { private: Triangle^ myTriangle; public: TestComponent() { myTriangle = gcnew Triangle( Point(5,5),Point(10,10),Point(1,8) ); } property Triangle^ MyTriangle { Triangle^ get() { return myTriangle; } void set( Triangle^ value ) { myTriangle = value; } } };
package Microsoft.Samples.InstanceDescriptorSample; import System.*; import System.ComponentModel.*; import System.ComponentModel.Design.Serialization.*; import System.Drawing.*; import System.Globalization.*; import System.Reflection.*; // This sample shows how to support code generation for a custom type // of object using a type converter and InstanceDescriptor objects. // To use this code, copy it to a file and add the file to a project. // Then add a component to the project and declare a Triangle field and // a public property with accessors for the Triangle field on the component. // The Triangle property will be persisted using code generation. /** @ attribute TypeConverter(Triangle.TriangleConverter .class.ToType()) */ public class Triangle { // Triangle members. private Point P1; private Point P2; private Point P3; /** @property */ public Point get_Point1() { return P1; } //get_Point1 /** @property */ public void set_Point1(Point value) { P1 = value; } //set_Point1 /** @property */ public Point get_Point2() { return P2; } //get_Point2 /** @property */ public void set_Point2(Point value) { P2 = value; } //set_Point2 /** @property */ public Point get_Point3() { return P3; } //get_Point3 /** @property */ public void set_Point3(Point value) { P3 = value; } //set_Point3 public Triangle(Point point1, Point point2, Point point3) { P1 = point1; P2 = point2; P3 = point3; } //Triangle // A TypeConverter for the Triangle object. Note that you can make it //internal,private, or any scope you want and the designers will still //be able to use it through the TypeDescriptor object. This type converter //provides the capability to convert to an InstanceDescriptor. This object //can be used by the .NET Framework to generate source code that creates an //instance of a Triangle object. class TriangleConverter extends TypeConverter { // This method overrides CanConvertTo from TypeConverter. //This is called when someone wants to convert an instance of Triangle //to another type. Here, only conversion to an InstanceDescriptor is //supported. public boolean CanConvertTo(ITypeDescriptorContext context , Type destinationType) { if (destinationType.Equals(InstanceDescriptor.class.ToType())) { return true; } // Always call the base to see if it can perform the conversion. return super.CanConvertTo(context, destinationType); } //CanConvertTo // This code performs the actual conversion from a Triangle to an //InstanceDescriptor. public Object ConvertTo(ITypeDescriptorContext context , CultureInfo culture, Object value, Type destinationType) { if (destinationType.Equals(InstanceDescriptor.class.ToType())) { ConstructorInfo ci = Triangle.class.ToType().GetConstructor( new Type[] { Point.class.ToType(), Point.class.ToType(), Point.class.ToType() }); Triangle t = ((Triangle)(value)); return new InstanceDescriptor(ci, new Object[] { t.get_Point1(), t.get_Point2(), t.get_Point3() }); } // Always call base, even if you can't convert. return super.ConvertTo(context, culture, value, destinationType); } //ConvertTo } //TriangleConverter } //Triangle public class TestComponent extends System.ComponentModel.Component { private Triangle myTriangle; public TestComponent() { myTriangle = new Triangle(new Point(5, 5), new Point(10, 10), new Point(1, 8)); } //TestComponent /** @property */ public Triangle get_MyTriangle() { return myTriangle; } //get_MyTriangle /** @property */ public void set_MyTriangle(Triangle value) { myTriangle = value; } //set_MyTriangle } //TestComponent

System.ComponentModel.Design.Serialization.InstanceDescriptor


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


InstanceDescriptor コンストラクタ (MemberInfo, ICollection, Boolean)
アセンブリ: System (system.dll 内)

Dim member As MemberInfo Dim arguments As ICollection Dim isComplete As Boolean Dim instance As New InstanceDescriptor(member, arguments, isComplete)
public function InstanceDescriptor ( member : MemberInfo, arguments : ICollection, isComplete : boolean )
- member
記述子のメンバ情報。これは、MethodInfo、ConstructorInfo、FieldInfo、または PropertyInfo である場合もあります。これが MethodInfo、FieldInfo、または PropertyInfo である場合は、static メンバを表している必要があります。


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


InstanceDescriptor コンストラクタ

名前 | 説明 |
---|---|
InstanceDescriptor (MemberInfo, ICollection) | メンバ情報と引数を指定して、InstanceDescriptor クラスの新しいインスタンスを初期化します。 |
InstanceDescriptor (MemberInfo, ICollection, Boolean) | メンバ情報、引数、およびこれらの情報がインスタンスの完全な記述であるかどうかを示す値を指定して、InstanceDescriptor クラスの新しいインスタンスを初期化します。 |

InstanceDescriptor コンストラクタ (MemberInfo, ICollection)
アセンブリ: System (system.dll 内)

Dim member As MemberInfo Dim arguments As ICollection Dim instance As New InstanceDescriptor(member, arguments)


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


InstanceDescriptor プロパティ

名前 | 説明 | |
---|---|---|
![]() | Arguments | このインスタンス記述子が表すオブジェクトのインスタンスを再構築するために使用できる引数のコレクションを取得します。 |
![]() | IsComplete | この InstanceDescriptor の内容でインスタンスを完全に識別できるかどうかを示す値を取得します。 |
![]() | MemberInfo | この記述子が関連付けられているインスタンスを記述するメンバ情報を取得します。 |

InstanceDescriptor メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | Invoke | このインスタンス記述子を呼び出し、記述子が記述するオブジェクトを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

InstanceDescriptor メンバ
オブジェクトのインスタンスを作成するために必要な情報を提供します。このクラスは継承できません。
InstanceDescriptor データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Arguments | このインスタンス記述子が表すオブジェクトのインスタンスを再構築するために使用できる引数のコレクションを取得します。 |
![]() | IsComplete | この InstanceDescriptor の内容でインスタンスを完全に識別できるかどうかを示す値を取得します。 |
![]() | MemberInfo | この記述子が関連付けられているインスタンスを記述するメンバ情報を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | Invoke | このインスタンス記述子を呼び出し、記述子が記述するオブジェクトを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- InstanceDescriptorのページへのリンク