Skip to content

implement a C# Interface in Python for .NET #674

Open

Description

@willhyper

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.

Activity

  1. den-run-ai commented on May 21, 2018

    @den-run-ai
    Contributor

    @willhyper is this something what you are looking for? scroll to the end of the issue with comments how this was implemented in pywebview:

    #567

  2. willhyper commented on May 24, 2018

    @willhyper
    Author

    @denfromufa Awesome! namespace is the missing single line that solves my question!

  3. den-run-ai commented on May 24, 2018

    @den-run-ai
    Contributor

    great, then let's close this issue. feel free to comment back.

  4. mkimberling commented on Apr 21, 2020

    @mkimberling

    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
  5. mhsmith commented on Jul 11, 2023

    @mhsmith

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions