次の方法で共有


ProxyAttribute コンストラクタ

ProxyAttribute クラスの新しいインスタンスを既定値で初期化します。

Public Sub New()
[C#]
public ProxyAttribute();
[C++]
public: ProxyAttribute();
[JScript]
public function ProxyAttribute();

使用例

 
<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

[C#] 
[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;
   }
}

[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);
   }
}

[C++] 
[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);
    }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

ProxyAttribute クラス | ProxyAttribute メンバ | System.Runtime.Remoting.Proxies 名前空間