ProvidePropertyAttribute-Klasse
Gibt den Namen der Eigenschaft an, die anderen Komponenten von einer Implementierung von IExtenderProvider angeboten wird. Diese Klasse kann nicht geerbt werden.
Namespace: System.ComponentModel
Assembly: System (in system.dll)
Syntax
'Declaration
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=True)> _
Public NotInheritable Class ProvidePropertyAttribute
Inherits Attribute
'Usage
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
Hinweise
Durch Markieren einer Klasse mit diesem Attribut weisen Sie den Codegenerator an, eine Extendereigenschaft mit dem angegebenen Namen zu erstellen. Die markierte Klasse muss IExtenderProvider implementieren. Infolgedessen kann die neue Eigenschaft von anderen Komponenten in einem Container verwendet werden.
Innerhalb der markierten Klasse müssen Sie die Get<Name>-Methode und die Set<Name>-Methode implementieren. Wenn Sie beispielsweise eine Klasse mit [ProvideProperty("PropertyName")] markieren, müssen Sie die GetPropertyName-Methode und die SetPropertyName-Methode implementieren. Um anzugeben, dass es sich bei der neuen Eigenschaft um eine Extendereigenschaft handelt, müssen Sie IExtenderProvider sowie eine CanExtend-Methode implementieren.
Weitere Informationen finden Sie unter Übersicht über Attribute und Erweitern von Metadaten mithilfe von Attributen.
Beispiel
Im folgenden Beispiel wird MyClass
mit einem ProvidePropertyAttribute markiert, das den Compiler anweist, die Eigenschaft MyProperty
mithilfe der GetMyProperty
-Methode und der SetMyProperty
-Methode zu erstellen.
<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
Vererbungshierarchie
System.Object
System.Attribute
System.ComponentModel.ProvidePropertyAttribute
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ProvidePropertyAttribute-Member
System.ComponentModel-Namespace