远程处理 - 对象是远程的吗?

时间:2009-11-02 20:32:34

标签: c# remoting

如何确定对象是本地还是远程(使用C#远程处理)?如果对象是远程的,则检查本地代码,如果从远程执行代码,则检查对象都可以。

2 个答案:

答案 0 :(得分:4)

    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

答案 1 :(得分:0)

我想您可以查看代理,看看它是否来自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");