ProvidePropertyAttribute クラス
IExtenderProvider の実装元が他のコンポーネントに提供するプロパティの名前を指定します。このクラスは継承できません。
名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文
'宣言
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=True)> _
Public NotInheritable Class ProvidePropertyAttribute
Inherits Attribute
'使用
Dim instance As ProvidePropertyAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]
public sealed class ProvidePropertyAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple=true)]
public ref class ProvidePropertyAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true) */
public final class ProvidePropertyAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)
public final class ProvidePropertyAttribute extends Attribute
解説
この属性でクラスをマークする場合は、指定した名前でエクステンダ プロパティを作成するようにコード ジェネレータに指示します。マークされたクラスは、IExtenderProvider を実装する必要があります。その結果、新しいプロパティをコンテナ内の他のコンポーネントで使用できるようになります。
マークされたクラスの内部で、Get <name> メソッドと Set <name> メソッドを実装する必要があります。たとえば、[ProvideProperty("PropertyName")] でクラスをマークした場合は、GetPropertyName メソッドと SetPropertyName メソッドを実装する必要があります。新しいプロパティをエクステンダ プロパティとして指定するには、IExtenderProvider から実装し、CanExtend メソッドも実装する必要があります。
詳細については、属性の概要、属性を使用したメタデータの拡張 の各トピックを参照してください。
使用例
MyClass
を ProvidePropertyAttribute でマークし、GetMyProperty
メソッドと SetMyProperty
メソッドから MyProperty
という名前のプロパティを作成するようにコンパイラに指示する例を次に示します。
<ProvideProperty("MyProperty", GetType(Control))> _
Public Class SampleClass
Implements IExtenderProvider
Protected ciMine As CultureInfo = Nothing
' Provides the Get portion of MyProperty.
Public Function GetMyProperty(myControl As Control) As CultureInfo
' Insert code here.
Return ciMine
End Function 'GetMyProperty
' Provides the Set portion of MyProperty.
Public Sub SetMyProperty(myControl As Control, value As String)
' Insert code here.
End Sub 'SetMyProperty
' When you inherit from IExtenderProvider, you must implement the
' CanExtend method.
Public Function CanExtend(target As [Object]) As Boolean Implements IExtenderProvider.CanExtend
Return TypeOf target Is Control
End Function 'CanExtend
' Insert additional code here.
End Class
[ProvideProperty("MyProperty", typeof(Control))]
public class MyClass : IExtenderProvider {
protected CultureInfo ciMine = null;
// Provides the Get portion of MyProperty.
public CultureInfo GetMyProperty(Control myControl) {
// Insert code here.
return ciMine;
}
// Provides the Set portion of MyProperty.
public void SetMyProperty(Control myControl, string value) {
// Insert code here.
}
/* When you inherit from IExtenderProvider, you must implement the
* CanExtend method. */
public bool CanExtend(Object target) {
return(target is Control);
}
// Insert additional code here.
}
[ProvideProperty("MyProperty",Control::typeid)]
public ref class MyClass: public IExtenderProvider
{
protected:
CultureInfo^ ciMine;
public:
// Provides the Get portion of MyProperty.
CultureInfo^ GetMyProperty( Control^ myControl )
{
// Insert code here.
return ciMine;
}
// Provides the Set portion of MyProperty.
void SetMyProperty( Control^ myControl, String^ value )
{
// Insert code here.
}
/* When you inherit from IExtenderProvider, you must implement the
* CanExtend method. */
virtual bool CanExtend( Object^ target )
{
return dynamic_cast<Control^>(target) != nullptr;
}
// Insert additional code here.
};
public class MyClass implements IExtenderProvider
{
protected CultureInfo ciMine = null;
// Provides the Get portion of MyProperty.
public CultureInfo GetMyProperty(Control myControl)
{
// Insert code here.
return ciMine;
} //GetMyProperty
// Provides the Set portion of MyProperty.
public void SetMyProperty(Control myControl, String value)
{
// Insert code here.
} //SetMyProperty
/* When you inherit from IExtenderProvider, you must implement the
* CanExtend method.
*/
public boolean CanExtend(Object target)
{
return target instanceof Control;
} //CanExtend
// Insert additional code here.
} //MyClass
継承階層
System.Object
System.Attribute
System.ComponentModel.ProvidePropertyAttribute
スレッド セーフ
この型の 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