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.
A:
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");
Preet Sangha
2009-11-02 20:38:04
Could you tell me some more details on how to do that? TransparentProxy seems to be an internal class and, well, very *transparent*.
eWolf
2009-11-02 20:41:49
+4
A:
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.");
brendan
2009-11-02 20:53:58
I voted for this answer because it provides the MSDN documentation link about a specific FCL method, and I like to see the thoughts of the framework creators referenced. Other options might exist but Microsoft explicitly accommodated this method.
John K
2009-11-02 21:01:19