RemotingServices.IsTransparentProxy(Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个布尔值,该值指示给定对象是透明代理还是实际对象。
public:
static bool IsTransparentProxy(System::Object ^ proxy);
public static bool IsTransparentProxy(object proxy);
static member IsTransparentProxy : obj -> bool
Public Shared Function IsTransparentProxy (proxy As Object) As Boolean
参数
- proxy
- Object
要检查的对象引用。
返回
一个布尔值,该值指示参数中指定的 proxy 对象是透明代理还是实际对象。
示例
下面的代码示例演示如何使用 IsTransparentProxy 该方法来确定对象是代理还是实际对象。 有关完整的示例代码,请参阅该 AsyncResult 类的示例。
// Creates an instance of a context-bound type SampleSynchronized.
SampleSynchronized^ sampSyncObj = gcnew SampleSynchronized;
// Checks whether the Object* is a proxy, since it is context-bound.
if ( RemotingServices::IsTransparentProxy( sampSyncObj ) )
Console::WriteLine( "sampSyncObj is a proxy." );
else
Console::WriteLine( "sampSyncObj is NOT a proxy." );
// Creates an instance of a context-bound type SampleSynchronized.
SampleSynchronized sampSyncObj = new SampleSynchronized();
// Checks whether the object is a proxy, since it is context-bound.
if (RemotingServices.IsTransparentProxy(sampSyncObj))
Console.WriteLine("sampSyncObj is a proxy.");
else
Console.WriteLine("sampSyncObj is NOT a proxy.");
' Creates an instance of a context-bound type SampleSynchronized.
Dim sampSyncObj As New SampleSynchronized()
' Checks whether the object is a proxy, since it is context-bound.
If RemotingServices.IsTransparentProxy(sampSyncObj) Then
Console.WriteLine("sampSyncObj is a proxy.")
Else
Console.WriteLine("sampSyncObj is NOT a proxy.")
End If
注解
跨任何类型的远程处理边界使用对象的客户端实际上使用对象的透明代理。 透明代理给人留下实际对象驻留在客户端空间中的印象。 它通过使用远程处理基础结构将对它发出的调用转发到实际对象来实现此目的。
透明代理本身由类型 RealProxy托管运行时类的实例所容纳。 实现 RealProxy 从透明代理转发操作所需的一部分功能。 代理对象继承托管对象的关联语义,例如垃圾回收、对成员和方法的支持,并且可以扩展为形成新类。 因此,代理具有双重性质;一方面,它需要充当与远程对象(透明代理)相同的类的对象,另一方面它是托管对象本身。
代理对象可以不考虑任何远程分区在一个 AppDomain. 应用程序不需要区分代理引用和对象引用。 但是,处理激活、生存期管理和事务等问题的服务提供商需要做出这样的区分。