C++/CLI 实现 C# 接口
C++/CLI Implementing a C# Interface
我有一个如下所示的 C# 界面:
public interface ITdcConnector
{
void Close(uint);
void FetchRequestAsync(ManagedFetchRequest);
UInt32 Open(String, Action<uint, ManagedFetchResponse>, out Int64);
}
我正在尝试像这样在 C++/CLI 中实现:
public ref class MockTdcConnector : public ITdcConnector
{
public:
virtual Void Close(UInt32);
Void FetchRequestAsync(ManagedFetchRequest);
UInt32 Open(String, Action<UInt32, ManagedFetchResponse^>^,
[System::Runtime::InteropServices::Out] Int64%);
};
IntelliSense 让我对 Open()
方法感到悲伤。它告诉我:IntelliSense: class fails to implement interface member function "ITdcConnector::Open"
我看过 few relevant examples 关于在 C++/CLI 中实现 C# 类 的文章,但没有成功。关于如何使 C++/cli 方法签名看起来像 C# 方法的任何想法?
所以,我直到刚才才看到这个。我开始在 C++/cli class 中键入 C# 方法的名称,IntelliSence 显示了它所期望的方法签名。我只需要更多 ^
和 virtual
。
这是我最终使用的,以供将来参考:
public ref class MockTdcConnector : public ITdcConnector
{
public:
virtual Void Close(UInt32);
virtual Void FetchRequestAsync(ManagedFetchRequest^);
virtual UInt32 Open(String^, Action<UInt32, ManagedFetchResponse^>^
[Runtime::InteropServices::Out] Int64%);
};
我有一个如下所示的 C# 界面:
public interface ITdcConnector
{
void Close(uint);
void FetchRequestAsync(ManagedFetchRequest);
UInt32 Open(String, Action<uint, ManagedFetchResponse>, out Int64);
}
我正在尝试像这样在 C++/CLI 中实现:
public ref class MockTdcConnector : public ITdcConnector
{
public:
virtual Void Close(UInt32);
Void FetchRequestAsync(ManagedFetchRequest);
UInt32 Open(String, Action<UInt32, ManagedFetchResponse^>^,
[System::Runtime::InteropServices::Out] Int64%);
};
IntelliSense 让我对 Open()
方法感到悲伤。它告诉我:IntelliSense: class fails to implement interface member function "ITdcConnector::Open"
我看过 few relevant examples 关于在 C++/CLI 中实现 C# 类 的文章,但没有成功。关于如何使 C++/cli 方法签名看起来像 C# 方法的任何想法?
所以,我直到刚才才看到这个。我开始在 C++/cli class 中键入 C# 方法的名称,IntelliSence 显示了它所期望的方法签名。我只需要更多 ^
和 virtual
。
这是我最终使用的,以供将来参考:
public ref class MockTdcConnector : public ITdcConnector
{
public:
virtual Void Close(UInt32);
virtual Void FetchRequestAsync(ManagedFetchRequest^);
virtual UInt32 Open(String^, Action<UInt32, ManagedFetchResponse^>^
[Runtime::InteropServices::Out] Int64%);
};