ProxyAttribute Class

Indicates that an object type requires a custom proxy.

Namespace: System.Runtime.Remoting.Proxies
Assembly: mscorlib (in mscorlib.dll)

'Declaration
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False, Inherited:=True)> _
Public Class ProxyAttribute
	Inherits Attribute
	Implements IContextAttribute
'Usage
Dim instance As ProxyAttribute

/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) */ 
public class ProxyAttribute extends Attribute implements IContextAttribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) 
public class ProxyAttribute extends Attribute implements IContextAttribute

Apply the current attribute to types that need custom proxies. 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. (Placing the proxy attribute on a child of MarshalByRefObject is not supported.)

NoteNote

This class makes a link demand and an inheritance demand at the class level. A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see Link Demands and Inheritance Demands.

<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.Infrastructure), _
AttributeUsage(AttributeTargets.Class)>  _
Public Class MyProxyAttribute
   Inherits ProxyAttribute

   Public Sub New()
   End Sub 'New

   ' 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

<MyProxyAttribute()> _
Public Class CustomServer
   Inherits ContextBoundObject

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

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

System.Object
   System.Attribute
    System.Runtime.Remoting.Proxies.ProxyAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: