implement a C# Interface in Python for .NET
Environment
- Pythonnet version: 2.3.0
- Python version: 3.6.5
- Operating System: Windows
Details
trying to implement a C# Interface in Python for .NET
This post exemplifies my exact problem. https://stackoverflow.com/questions/49736531/implement-a-c-sharp-interface-in-python-for-net#
However, I found relatively few discussion and solution. Forgive me raise the issue here. :) I am not sure if this is an intent for pythonnet not to support. If so, reasons are welcomed. Otherwise, I find the practice (implementing an interface) is common, and so why there is no support. My use case is, I am given a dll. The interface is defined there. I want to develop Python class that implements the interface. Without this approach viable, I foresee my developed application would then be half in C# and half in Python, which I consider ugly.
@willhyper is this something what you are looking for? scroll to the end of the issue with comments how this was implemented in pywebview:
https://github.com/pythonnet/pythonnet/issues/567
@denfromufa Awesome! namespace is the missing single line that solves my question!
great, then let's close this issue. feel free to comment back.
I was recently confused by this and had to do alot of googling to find the answer on Stack Overflow.
It would be a great improvement to have
- an example in the docs
- an example of implementing the interface in test_interface.py
The documentation is seriously incomplete in this area. All it currently says about Python subclasses of .NET base classes is here:
Managed classes can also be subclassed in Python, though members of the Python subclass are not visible to .NET code. See the helloform.py file in the /demo directory of the distribution for a simple Windows Forms example that demonstrates subclassing a managed class.
Since methods are "members", this made me think that overriding methods was not possible. And the linked example did nothing to correct that misunderstanding.
Perhaps it would be better to link to these tests, which inherit from these C# base classes.