ProvidePropertyAttribute Klasa

Definicja

Określa nazwę właściwości, którą implementator IExtenderProvider oferuje innym składnikom. Klasa ta nie może być dziedziczona.

public ref class ProvidePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class ProvidePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)>]
type ProvidePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class ProvidePropertyAttribute
Inherits Attribute
Dziedziczenie
ProvidePropertyAttribute
Atrybuty

Przykłady

Poniższe przykładowe znaczniki z elementem ProvidePropertyAttribute , który informuje kompilator o utworzeniu właściwości wywoływanej MyPropertyGetMyProperty z metod i SetMyProperty .MyClass

[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.
};
[ProvideProperty("MyProperty", typeof(Control))]
public class MyClass : IExtenderProvider
{
    protected CultureInfo ciMine;
    // Provides the Get portion of MyProperty. 
    public CultureInfo GetMyProperty(Control myControl) =>
        // Insert code here.
        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) => target is Control;

    // Insert additional code here.
}
<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

    ' 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

Uwagi

Po oznaczeniu klasy za pomocą tego atrybutu należy poinformować generator kodu o utworzeniu właściwości rozszerzenia o podanej nazwie. Oznaczona klasa musi implementować element IExtenderProvider. W związku z tym nowa właściwość może być używana przez inne składniki w kontenerze.

W oznaczonej klasie należy zaimplementować Get<metody nazw> i Set<nazw> . Jeśli na przykład oznaczysz klasę [ProvideProperty("PropertyName")], musisz zaimplementować GetPropertyName metody i SetPropertyName . Aby określić, że nowa właściwość będzie właściwością rozszerzenia, należy zaimplementować metodę CanExtend z IExtenderProviderklasy .

Aby uzyskać więcej informacji, zobacz Atrybuty.

Konstruktory

Nazwa Opis
ProvidePropertyAttribute(String, String)

Inicjuje ProvidePropertyAttribute nowe wystąpienie klasy o nazwie właściwości i typie jej odbiornika.

ProvidePropertyAttribute(String, Type)

Inicjuje nowe wystąpienie ProvidePropertyAttribute klasy o nazwie właściwości i jej Typewłaściwości .

Właściwości

Nazwa Opis
PropertyName

Pobiera nazwę właściwości, którą udostępnia ta klasa.

ReceiverTypeName

Pobiera nazwę typu danych, który może rozszerzyć ta właściwość.

TypeId

Pobiera unikatowy identyfikator tego atrybutu.

Metody

Nazwa Opis
Equals(Object)

Zwraca, czy wartość danego obiektu jest równa bieżącej ProvidePropertyAttributewartości .

GetHashCode()

Zwraca kod skrótu dla tego wystąpienia.

GetType()

Pobiera Type bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

Po zastąpieniu w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną dla klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po zastąpieniu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Object.

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

Nazwa Opis
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do uzyskania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Zapewnia dostęp do właściwości i metod uwidocznionych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy