如何在IronPython中实现界面?

时间:2022-09-02 09:12:20

The FAQ that comes with IronPython 2.0.1 says the following:

IronPython 2.0.1附带的常见问题解答说明如下:

You can define interfaces in C#, build those into a DLL, and then implement those interfaces in Python code as well as pass the python objects that implement the interfaces to C# code.

您可以在C#中定义接口,将它们构建到DLL中,然后在Python代码中实现这些接口,并将实现接口的python对象传递给C#代码。

I have googled and googled and googled, but haven't found how to do this. Can someone help?

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

1 个解决方案

#1


19  

I'm not sure of this, but it looks like you could do it with the regular inheritance syntax of python:

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

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

EDIT: Ok, I just tested it and confirmed that you can implement an interface in IronPython this way. Just "inherit" the interface, implement its methods as you would any other class method, and enjoy!

编辑:好的,我刚测试它并确认你可以用这种方式在IronPython中实现一个接口。只需“继承”接口,实现其方法就像任何其他类方法一样,享受!

#1


19  

I'm not sure of this, but it looks like you could do it with the regular inheritance syntax of python:

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

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

EDIT: Ok, I just tested it and confirmed that you can implement an interface in IronPython this way. Just "inherit" the interface, implement its methods as you would any other class method, and enjoy!

编辑:好的,我刚测试它并确认你可以用这种方式在IronPython中实现一个接口。只需“继承”接口,实现其方法就像任何其他类方法一样,享受!