是否可以从另一个单独的 .NET AppDomian 更改 .NET AppDomain 中的字符串属性的值

发布于 2024-09-27 20:46:48 字数 165 浏览 8 评论 0原文

假设两个 AppDomain 在同一进程中运行,是否可以从另一个单独的 .NET AppDomain 更改给定 .NET AppDomain 中类的公共属性(类型字符串)的值。另一个重要的假设是,在包含该属性的 AppDomain 中运行的代码不能被修改.. 即.. 进行任何更改后重新编译。

谢谢!

Is it possible to change the value of a public property (type string) of a class within a given .NET AppDomain from another separate .NET AppDomain assuming both AppDomain's are running in the same process. The other important assumption is that the code running in the AppDomain that contains the property can not be modified .. ie .. recompiled with any changes.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2024-10-04 20:46:48

当然。您只需通过 MarshalByRef 对象公开对该属性的访问,该对象将允许 AppDomain A 中的一个实例接触并触摸 AppDomain B 中的属性。

以下是将从 AppDomain A 在 AppDomain B 中实例化的类的一个简单示例:

   internal class SomeLinkClass : MarshalByRefObject
   {
      internal void UpdateProperty(string newValue)
      {
         // this function actually will execute within AppDomain B

         // somehow get access to the property and then set it 
         // with the new value.
      }
   }

以下是如何从 AppDomain A 使用它:

// somehow you need to get a ref to AppDomain B
    SomeLinkClass linkClass = appDomainB.CreateInstanceFromAndUnwrap(
                                  Assembly.GetExecutingAssembly().Location,
                                  typeof(SomeLinkClass).FullName) as SomeLinkClass;

Sure. You just need to expose access to the property via a MarshalByRef object that will allow one instance in AppDomain A to reach out and touch the property in AppDomain B.

Here is a simple example of the class that would be instantiated in AppDomain B from AppDOmain A:

   internal class SomeLinkClass : MarshalByRefObject
   {
      internal void UpdateProperty(string newValue)
      {
         // this function actually will execute within AppDomain B

         // somehow get access to the property and then set it 
         // with the new value.
      }
   }

And here is how you would consume it from AppDomain A:

// somehow you need to get a ref to AppDomain B
    SomeLinkClass linkClass = appDomainB.CreateInstanceFromAndUnwrap(
                                  Assembly.GetExecutingAssembly().Location,
                                  typeof(SomeLinkClass).FullName) as SomeLinkClass;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文