ProvidePropertyAttribute Clase

Definición

Especifica el nombre de la propiedad que un implementador de IExtenderProvider ofrece a otros componentes. Esta clase no puede heredarse.

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
Herencia
ProvidePropertyAttribute
Atributos

Ejemplos

En el ejemplo siguiente se marca MyClass con un ProvidePropertyAttribute que indica al compilador que cree una propiedad llamada MyProperty a partir de los GetMyProperty métodos y 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

Comentarios

Al marcar una clase con este atributo, se indica al generador de código que cree una propiedad extensor con el nombre que proporcione. La clase marcada debe implementar IExtenderProvider. Como resultado, otros componentes de un contenedor pueden usar la nueva propiedad.

Dentro de la clase marcada, debe implementar Get<métodos name> y Set<name> . Por ejemplo, si marca una clase con [ProvideProperty("PropertyName")], debe implementar GetPropertyName y SetPropertyName métodos. Para especificar que la nueva propiedad será una propiedad extensor, debe implementar desde IExtenderProvider, también debe implementar un CanExtend método .

Para obtener más información, consulte Attributes (Atributos).

Constructores

Nombre Description
ProvidePropertyAttribute(String, String)

Inicializa una nueva instancia de la ProvidePropertyAttribute clase con el nombre de la propiedad y el tipo de su receptor.

ProvidePropertyAttribute(String, Type)

Inicializa una nueva instancia de la ProvidePropertyAttribute clase con el nombre de la propiedad y su Type.

Propiedades

Nombre Description
PropertyName

Obtiene el nombre de una propiedad que proporciona esta clase.

ReceiverTypeName

Obtiene el nombre del tipo de datos que puede extender esta propiedad.

TypeId

Obtiene un identificador único para este atributo.

Métodos

Nombre Description
Equals(Object)

Devuelve si el valor del objeto especificado es igual al actual ProvidePropertyAttribute.

GetHashCode()

Devuelve el código hash de esta instancia.

GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
IsDefaultAttribute()

Cuando se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.

(Heredado de Attribute)
Match(Object)

Cuando se reemplaza en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.

(Heredado de Attribute)
MemberwiseClone()

Crea una copia superficial del Objectactual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Implementaciones de interfaz explícitas

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

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.

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

Recupera la información de tipo de un objeto, que se puede usar para obtener la información de tipo de una interfaz.

(Heredado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).

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

Proporciona acceso a propiedades y métodos expuestos por un objeto .

(Heredado de Attribute)

Se aplica a