【问题标题】:How do you implement an interface in IronPython?如何在 IronPython 中实现接口?
【发布时间】:2010-10-16 07:25:36
【问题描述】:

FAQ that comes with IronPython 2.0.1 表示以下内容:

您可以在 C# 中定义接口,构建 将它们放入 DLL 中,然后执行 Python代码中的那些接口为 以及传递 python 对象 实现 C# 代码的接口。

我已经用谷歌搜索和搜索,但还没有找到如何做到这一点。有人可以帮忙吗?

【问题讨论】:

    标签: .net interface ironpython


    【解决方案1】:

    我不确定这一点,但看起来你可以使用 python 的常规继承语法来做到这一点:

    class SomeClass (ISomeInterface):
        def SomeMethod(self, parameter):
            pass
    

    编辑:好的,我刚刚对其进行了测试并确认您可以通过这种方式在 IronPython 中实现接口。只需“继承”接口,像任何其他类方法一样实现其方法,然后享受吧!

    【讨论】:

    • 要在接口中实现属性,您可以使用def get_SomeProperty(self):def set_SomeProperty(self):
    猜你喜欢
    • 1970-01-01
    • 2012-01-22
    • 2013-04-27
    • 2017-06-30
    • 2020-04-30
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多