Python for.Net和C#extensions SignalR客户端(方法不工作)

2024-09-30 06:18:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图进入Microsoft.Signal库,其中一些Hub(IHubProxy)的实现在一个扩展中:HubProxyExtensions

pythonfor.Net在自述文件中似乎没有包含扩展,我也找不到任何参考(我的googlefu在本例中不起作用)

我可以直接加载extensions类,但调用方法失败:

ext = SignalR.Client.HubProxyExtensions
ext.On(self._proxy, method, handle)

扩展类作为一个元类加载和报告,并具有来自即时窗口的方法

^{pr2}$

调用ext.On()会使进程崩溃。在

pythonfor.Net是否支持扩展?(或者它只是特定于这个特定实现的问题)


更新:在扩展上做一个简单的测试,看起来pythonfor.Net确实正确地处理了扩展,所以我对Signalr的调用有问题。。。更多的测试即将到来。在


Tags: 方法signalneton自述文件extensionsextmicrosoft
1条回答
网友
1楼 · 发布于 2024-09-30 06:18:27

所以我要回答我自己的问题,因为这是多个问题;我没有看到其他人直接解决这个问题。在


操作模板

在我的例子中,问题是没有办法在pythonfor.Net中绑定操作模板。因此,在集线器中无法调用正确的On方法。在

Someone else found the same issue recently


扩展

Python for.Net可以调用扩展方法;只需像其他静态类方法一样通过扩展类调用静态扩展方法。在

C#

namespace ExtensionTest
{
    public class MyClass
    {
        public string MyMethod(string something)
        {
            System.Console.Out.WriteLine(string.Format("Hi! This is something! {0}", something));
            return something + " something else";
        }
    }
}

namespace ExtensionTest
{
    public static class MyExtension
    {
        public static string MyExtensionMethod(this MyClass myclass, string something)
        {
            System.Console.Out.WriteLine(string.Format("This is the extension {0}", something));
            string somethingelse = myclass.MyMethod(something);
            return somethingelse + " more of something";
        }
    }
}

Python:

^{pr2}$

输出:

Hi! This is something! Hi
Hi something else
This is the extension Hello!
Hi! This is something! Hello!
Hello! something else more of something

我不知道为什么python for.net的自述文件中没有提到这一点。在

我想这很明显:)

相关问题 更多 >

    热门问题