共用方式為


ProxyAttribute.CreateProxy(ObjRef, Type, Object, Context) 方法

定義

ObjRef 所描述而位於伺服器上的遠端物件建立遠端 Proxy 的執行個體。

public:
 virtual System::Runtime::Remoting::Proxies::RealProxy ^ CreateProxy(System::Runtime::Remoting::ObjRef ^ objRef, Type ^ serverType, System::Object ^ serverObject, System::Runtime::Remoting::Contexts::Context ^ serverContext);
public virtual System.Runtime.Remoting.Proxies.RealProxy CreateProxy (System.Runtime.Remoting.ObjRef objRef, Type serverType, object serverObject, System.Runtime.Remoting.Contexts.Context serverContext);
[System.Security.SecurityCritical]
public virtual System.Runtime.Remoting.Proxies.RealProxy CreateProxy (System.Runtime.Remoting.ObjRef objRef, Type serverType, object serverObject, System.Runtime.Remoting.Contexts.Context serverContext);
abstract member CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
override this.CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
[<System.Security.SecurityCritical>]
abstract member CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
override this.CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
Public Overridable Function CreateProxy (objRef As ObjRef, serverType As Type, serverObject As Object, serverContext As Context) As RealProxy

參數

objRef
ObjRef

要為其建立 Proxy 之遠端物件的物件參考。

serverType
Type

遠端物件所位在之伺服器的類型。

serverObject
Object

伺服器物件。

serverContext
Context

伺服器物件所位在的內容。

傳回

指定之 ObjRef 中所描述遠端物件的遠端 Proxy 的新執行個體。

屬性

範例

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

備註

注意

當 Proxy 從參考以 ProxyAttribute 屬性標示的類別的實例中建立 ObjRef Proxy 時,就會呼叫目前的方法。 因此,只有在 ObjRef 從呼叫的傳回或參數收到 時,或在用戶端啟動對象期間收到 時,才會使用方法。 ProxyAttribute不適用於已知的物件類型。

適用於