简体   繁体   中英

Remoting - Is an object remote?

How can I determine whether an object is local or remote (using C# remoting)? Both checking in local code if the object is remote or in the object if the code is executed from remote would be okay.

    if(System.Runtime.Remoting.RemotingServices.IsTransparentProxy(myObject))
      Console.WriteLine("Yay - my object is a remoted object.");
    else
      Console.WriteLine("Boo - my object is not a remoted object.");

MSDN Docs on IsTransparentProxy

I suppose you could look at the proxy and see if it derived from TransparentProxy

var myObj = ....;
if(myObj is TransparentProxy) 
  Console.WriteLine("I have a remote object");
else 
  Console.WriteLine("I don't think I have a remote object");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM