ProvidePropertyAttribute Classe

Definição

Especifica o nome da propriedade que um implementador de IExtenderProvider oferece a outros componentes. Esta classe não pode ser herdada.

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
Herança
ProvidePropertyAttribute
Atributos

Exemplos

O exemplo seguinte marca MyClass com a ProvidePropertyAttribute que diz ao compilador para criar uma propriedade chamada MyProperty dos GetMyProperty métodos e 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;
    // 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

Observações

Quando marcas uma classe com este atributo, dizes ao gerador de código para criar uma propriedade extensor com o nome que forneces. A classe marcada deve implementar IExtenderProvider. Como resultado, a nova propriedade pode ser usada por outros componentes num contentor.

Dentro da classe marcada, deve implementar Get<> nomes e Set<métodos de nome.> Por exemplo, se marcar uma classe com [ProvideProperty("PropertyName")], deve implementar GetPropertyName and SetPropertyName methods. Para especificar que a nova propriedade será uma propriedade extensor, deve implementar a partir de IExtenderProvider, deve também implementar um CanExtend método.

Para obter mais informações, consulte Atributos.

Construtores

Name Description
ProvidePropertyAttribute(String, String)

Inicializa uma nova instância da ProvidePropertyAttribute classe com o nome da propriedade e o tipo do seu recetor.

ProvidePropertyAttribute(String, Type)

Inicializa uma nova instância da ProvidePropertyAttribute classe com o nome da propriedade e o seu Type.

Propriedades

Name Description
PropertyName

Recebe o nome de uma propriedade que esta classe fornece.

ReceiverTypeName

Obtém o nome do tipo de dado que esta propriedade pode estender.

TypeId

Obtém um identificador único para este atributo.

Métodos

Name Description
Equals(Object)

Devolve se o valor do objeto dado é igual à corrente ProvidePropertyAttribute.

GetHashCode()

Devolve o código de hash para esta instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Quando sobrescrito numa classe derivada, indica se o valor desta instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando sobrescrito numa classe derivada, devolve um valor que indica se esta instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Implementações de Interface Explícita

Name Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de despacho.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera a informação de tipo de um objeto, que pode ser usada para obter a informação de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera o número de interfaces de informações de tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a