gpt4 book ai didi

c# - 原始类型的透明代理

转载 作者:行者123 更新时间:2023-11-30 17:16:42 27 4
gpt4 key购买 nike

我有一个 {System.Runtime.Remoting.Proxies.__TransparentProxy} 类型的运行时对象,它是从继承自 ContextBoundObject 的类实例创建的。此类向其他对象引发事件,我需要将此代理对象转换为原始对象。所有对象都在单个系统上的默认 AppDomain 中。

public abstract class ObjectBase : ContextBoundObject, IObjectBase
{
}

public IMessageSink GetObjectSink(MarshalByRefObject o, IMessageSink next)
{
_context = (ObjectBase)o;// as ObjectBase; does not give any error but type remains
/// transparent proxy in VS watch window.
// no property to get the underlying type of the proxy
return _aspect;
}

如何将它们转换成原始对象?如果在同一内存上运行,为什么会创建代理

最佳答案

您可以通过调用 MarshalServices.GetRealProxy() 获取透明代理的 RealProxy 实例, 但获取服务器对象引用会更难,因为默认的 RealProxy 只有非公共(public)成员公开此引用( protected 方法 GetUnwrappedServer() 和内部属性 UnwrappedServerObject) .如果 RealProxy 是您自己实现的,或者通过反射实现的(如果您有足够的信任来执行此操作),您可以访问这些。

关于c# - 原始类型的透明代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7059936/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com