Search code examples
.netinterfaceironpython

How do you implement an interface in IronPython?


The FAQ that comes with IronPython 2.0.1 says the following:

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.

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


Solution

  • You can do it with the regular inheritance syntax of Python:

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

    Just "inherit" the interface, implement its methods as you would any other class method, and enjoy!