在 IronPython 中重新声明 .net 类

发布于 2024-07-24 08:58:10 字数 80 浏览 3 评论 0原文

谁能告诉我是否可以在 IronPython 中重新声明 C# 类? 如果我有一个 C# 类,我可以从 IronPython 对其进行猴子修补吗?

Can anyone tell me if its possible to redeclare a C# class in IronPython? If I have a C# class, would I be able to monkey-patch it from IronPython?

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

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

发布评论

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

评论(3

友谊不毕业 2024-07-31 08:58:10

您无法从 IronPython 进行猴子修补。 IronPython 对待所有 .NET 类就像 CPython 对待内置类型一样:它们不能被猴子修补。 另一方面,IronRuby 确实支持这一点。

You cannot monkey patch from IronPython. IronPython treats all .NET classes just like CPython treats built-in types: they cannot be monkey patched. IronRuby on the other hand does support this.

私藏温柔 2024-07-31 08:58:10

您可以从 IronPython 进行猴子补丁,但 IPy 是唯一尊重您的更改的环境; 即,如果您尝试从 IronPython 模拟 File.Create,这对于任何 IPy 代码都可以正常工作,但如果您调用名为 File.Create 的 C# 方法,它将获得真实的方法,而不是模拟的。

You can monkey-patch from IronPython, but IPy is the only environment that will respect your changes; i.e. if you tried to mock out File.Create from IronPython, this would work fine for any IPy code, but if you called a C# method which called File.Create, it would get the real one, not the mock.

笨死的猪 2024-07-31 08:58:10

为什么要重新声明呢? 将其子类化或者只是创建一个全新的不是更有意义吗?班级?

编辑:请澄清一下,我认为您真正需要的是一个适当的控制反转(IOC)框架,例如 温莎城堡。 基本上,您有一个数据库接口,然后配置 IOC 框架以注入用于生产的真实数据库和用于测试的模拟数据库。

Why would you redeclare it? Wouldn't it make more sense to subclass it or just make a totally new class?

EDIT: Give your clarification, I think what you actually need is a proper inversion of control (IOC) framework, such as Castle Windsor. Basically, you have a database interface, then configure the IOC framework to inject a real database for production, and mock database for testing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文