ProxyAttribute ProxyAttribute ProxyAttribute ProxyAttribute Class

Definición

Indica que un tipo de objeto requiere un proxy personalizado.Indicates that an object type requires a custom proxy.

public ref class ProxyAttribute : Attribute, System::Runtime::Remoting::Contexts::IContextAttribute
[System.AttributeUsage(System.AttributeTargets.Class)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
[System.Security.SecurityCritical]
public class ProxyAttribute : Attribute, System.Runtime.Remoting.Contexts.IContextAttribute
type ProxyAttribute = class
    inherit Attribute
    interface IContextAttribute
Public Class ProxyAttribute
Inherits Attribute
Implements IContextAttribute
Herencia
ProxyAttributeProxyAttributeProxyAttributeProxyAttribute
Atributos
Implementaciones

Ejemplos

[AttributeUsageAttribute(AttributeTargets::Class)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::LinkDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::InheritanceDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
public ref class MyProxyAttribute: public ProxyAttribute
{
public:
   MyProxyAttribute(){}

   // Create an instance of ServicedComponentProxy
   virtual MarshalByRefObject^ CreateInstance( Type^ serverType ) override
   {
      return ProxyAttribute::CreateInstance( serverType );
   }

   virtual RealProxy^ CreateProxy( ObjRef^ objRef1, Type^ serverType, Object^ serverObject, Context^ serverContext ) override
   {
      MyProxy^ myCustomProxy = gcnew MyProxy( serverType );
      if ( serverContext != nullptr )
      {
         RealProxy::SetStubData( myCustomProxy, serverContext );
      }

      if ( ( !serverType->IsMarshalByRef) && (serverContext == nullptr) )
      {
         throw gcnew RemotingException( "Bad Type for CreateProxy" );
      }

      return myCustomProxy;
   }
};

[MyProxyAttribute]
ref class CustomServer: public ContextBoundObject
{
public:
   CustomServer()
   {
      Console::WriteLine( "CustomServer Base Class constructor called" );
   }

   void HelloMethod( String^ str )
   {
      Console::WriteLine( "HelloMethod of Server is invoked with message : {0}", str );
   }
};
[AttributeUsage(AttributeTargets.Class)]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.Infrastructure)]
public class MyProxyAttribute : ProxyAttribute
{
   public MyProxyAttribute()
   {
   }
   // Create an instance of ServicedComponentProxy
   public override MarshalByRefObject CreateInstance(Type serverType)
   {  
      return base.CreateInstance(serverType);
   }
   public override RealProxy CreateProxy(ObjRef objRef1,
      Type serverType,
      object serverObject,
      Context serverContext)
   {
      MyProxy myCustomProxy = new MyProxy(serverType);
      if(serverContext != null)
      {
         RealProxy.SetStubData(myCustomProxy,serverContext);
      }
      if((!serverType.IsMarshalByRef)&&(serverContext == null))
      {
         throw new RemotingException("Bad Type for CreateProxy");
      }
      return myCustomProxy;
   }
}
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
[MyProxyAttribute]
public class CustomServer :ContextBoundObject
{
   public CustomServer()
   {
      Console.WriteLine("CustomServer Base Class constructor called");
   }
   public void HelloMethod(string str)
   {
      Console.WriteLine("HelloMethod of Server is invoked with message : " + str);
   }
}
<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.Infrastructure), _
AttributeUsage(AttributeTargets.Class)>  _
Public Class MyProxyAttribute
   Inherits ProxyAttribute

   Public Sub New()
   End Sub

   ' Create an instance of ServicedComponentProxy
   Public Overrides Function CreateInstance(serverType As Type) As MarshalByRefObject
      Return MyBase.CreateInstance(serverType)
   End Function 'CreateInstance

   Public Overrides Function CreateProxy(objRef1 As ObjRef, serverType As Type, _
               serverObject As Object, serverContext As Context) As RealProxy
      Dim myCustomProxy As New MyProxy(serverType)
      If Not (serverContext Is Nothing) Then
         RealProxy.SetStubData(myCustomProxy, serverContext)
      End If
      If Not serverType.IsMarshalByRef And serverContext Is Nothing Then
         Throw New RemotingException("Bad Type for CreateProxy")
      End If
      Return myCustomProxy
   End Function 'CreateProxy
End Class

<MyProxyAttribute()> _
Public Class CustomServer
   Inherits ContextBoundObject

   Public Sub New()
      Console.WriteLine("CustomServer Base Class constructor called")
   End Sub

   Public Sub HelloMethod(str As String)
      Console.WriteLine("HelloMethod of Server is invoked with message : " + str)
   End Sub
End Class

Comentarios

Aplique el atributo actual a los tipos que necesitan servidores proxy personalizados.Apply the current attribute to types that need custom proxies. Puede usar la clase ProxyAttribute para interceptar la new instrucciónNew (en Visual Basic) derivando del ProxyAttribute y colocando el atributo en un elemento secundario ContextBoundObjectde.You can use the ProxyAttribute class to intercept the new (New in Visual Basic) statement by deriving from the ProxyAttribute and placing the attribute on a child of ContextBoundObject. (No se admite la colocación del atributo de MarshalByRefObject proxy en un elemento secundario de).(Placing the proxy attribute on a child of MarshalByRefObject is not supported.)

Nota

Esta clase realiza una petición de vínculo y una petición de herencia en el nivel de clase.This class makes a link demand and an inheritance demand at the class level. Se SecurityException produce una excepción cuando el llamador inmediato o la clase derivada no tienen permiso de infraestructura.A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. Para obtener más información sobre las demandas de seguridad, consulte peticiones de vínculo y peticiones de herencia.For details about security demands, see Link Demands and Inheritance Demands.

Constructores

ProxyAttribute() ProxyAttribute() ProxyAttribute() ProxyAttribute()

Inicializa una nueva instancia de la clase ProxyAttribute con valores predeterminados.Initializes a new instance of the ProxyAttribute class with default values.

Métodos

CreateInstance(Type) CreateInstance(Type) CreateInstance(Type) CreateInstance(Type)

Crea un MarshalByRefObject inicializado o un proxy transparente, en función de si el tipo especificado puede existir en el contexto actual.Creates either an uninitialized MarshalByRefObject or a transparent proxy, depending on whether the specified type can exist in the current context.

CreateProxy(ObjRef, Type, Object, Context) CreateProxy(ObjRef, Type, Object, Context) CreateProxy(ObjRef, Type, Object, Context) CreateProxy(ObjRef, Type, Object, Context)

Crea una instancia de un proxy de comunicación remota para un objeto remoto descrito por el ObjRef especificado, que se encuentra en el servidor.Creates an instance of a remoting proxy for a remote object described by the specified ObjRef, and located on the server.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Devuelve un valor que indica si esta instancia es igual que un objeto especificado.Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Devuelve el código hash de esta instancia.Returns the hash code for this instance.

(Inherited from Attribute)
GetPropertiesForNewContext(IConstructionCallMessage) GetPropertiesForNewContext(IConstructionCallMessage) GetPropertiesForNewContext(IConstructionCallMessage) GetPropertiesForNewContext(IConstructionCallMessage)

Obtiene las propiedades para un nuevo contexto.Gets properties for a new context.

GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
IsContextOK(Context, IConstructionCallMessage) IsContextOK(Context, IConstructionCallMessage) IsContextOK(Context, IConstructionCallMessage) IsContextOK(Context, IConstructionCallMessage)

Comprueba el contexto especificado.Checks the specified context.

IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Implementaciones de interfaz explícitas

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

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Propiedades

TypeId TypeId TypeId TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Seguridad

SecurityPermission
Para trabajar con código de infraestructura.For operating with infrastructure code. Valor de petición InheritanceDemand:; Valor de permiso:InfrastructureDemand value: InheritanceDemand; Permission Value: Infrastructure

Se aplica a

Consulte también: