Export (0) Print
Expand All

ProxyAttribute Class

Indicates that an object type requires a custom proxy.

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

[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
[ComVisibleAttribute(true)]
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public class ProxyAttribute : Attribute, 
	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.

[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);
   }
}
[AttributeUsage(AttributeTargets::Class)]
[System::Security::Permissions::SecurityPermissionAttribute(System::Security::Permissions::SecurityAction::Demand, Flags=SecurityPermissionFlag::Infrastructure)] 

public __gc class MyProxyAttribute : public ProxyAttribute 
{
public:
    MyProxyAttribute() 
    {
    }
    // Create an instance of ServicedComponentProxy
public:
    MarshalByRefObject* CreateInstance(Type* serverType) 
    {  
        return ProxyAttribute::CreateInstance(serverType);
    }
public:
    RealProxy* CreateProxy(ObjRef* objRef1,
        Type* serverType,
        Object* serverObject,
        Context* serverContext) 
    {
        MyProxy* myCustomProxy = new MyProxy(serverType);
        if (serverContext != 0) 
        {
            RealProxy::SetStubData(myCustomProxy, serverContext);
        }
        if ((!serverType->IsMarshalByRef)&&(serverContext == 0)) {
            throw new RemotingException(S"Bad Type for CreateProxy");
        }
        return myCustomProxy;
    }
};

[MyProxyAttribute]
__gc class CustomServer : public ContextBoundObject 
{
public:
    CustomServer() 
    {
        Console::WriteLine(S"CustomServer Base Class constructor called");
    }
public:
    void HelloMethod(String* str) {
        Console::WriteLine(S"HelloMethod of Server is invoked with message : {0}", str);
    }
};

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft