ProvidePropertyAttribute Klasa

Definicja

Określa nazwę właściwości, którą implementuje oferty IExtenderProvider 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
public sealed class ProvidePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)>]
type ProvidePropertyAttribute = class
    inherit Attribute
type ProvidePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class ProvidePropertyAttribute
Inherits Attribute
Dziedziczenie
ProvidePropertyAttribute
Atrybuty

Przykłady

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

[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 = 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", 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ć IExtenderProviderelement . 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 IExtenderProviderprogramu .

Aby uzyskać więcej informacji, zobacz Atrybuty.

Konstruktory

ProvidePropertyAttribute(String, String)

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

ProvidePropertyAttribute(String, Type)

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

Właściwości

PropertyName

Pobiera nazwę właściwości zapewnianej przez tę klasę.

ReceiverTypeName

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

TypeId

Pobiera unikatowy identyfikator tego atrybutu.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego elementu Attribute.

(Odziedziczone po Attribute)

Metody

Equals(Object)

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

GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
IsDefaultAttribute()

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

(Odziedziczone po Attribute)
Match(Object)

W przypadku zastąpienia 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 Objectelementu .

(Odziedziczone po Object)
ToString()

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

(Odziedziczone po Object)

Jawne implementacje interfejsu

_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 pobrania informacji o typie 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)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy