我得到了一个用 C# 编写的库,我正在尝试使用 Python for .NET 调用它。
我需要一个实例的主类有一个构造函数,如:
GDhuClient(IGDhuSettings)
Run Code Online (Sandbox Code Playgroud)
没有(公开的)实现IGDhuSettings
接口的类。当我创建一个 Python 类来实现它时,例如,
class PyGDhuSettings(IGDhuSettings):
...
Run Code Online (Sandbox Code Playgroud)
TypeError: interface takes exactly one argument
如果我没有__new__
方法或者我以正常方式定义一个方法,我会得到:
def __new__(cls):
return super().__new__(cls)
Run Code Online (Sandbox Code Playgroud)
如果我尝试实例化接口,就好像它是一个类,我要么得到相同的错误(没有或 >1 个参数),要么<whatever> does not implement IGDhuSettings
我传递一个参数。
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Python.Runtime
{
/// <summary>
/// Provides the implementation for reflected interface types. Managed
/// interfaces are represented in Python by actual Python type objects.
/// Each of those …
Run Code Online (Sandbox Code Playgroud)