在IronPython中访问.NET类方法重载时出错 [英] Errors accessing .NET class method overloads in IronPython

查看:112
本文介绍了在IronPython中访问.NET类方法重载时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#编写的类.该类有两种方法,签名为:

I have a class I've written in C#. The class has two methods, the signatures being:

bool Navigate(string url)
bool Navigate(Uri url)

根据我的收集,IronPython运行时应该尝试根据传入的参数来选择最佳的重载.就我而言,我传入了一个我知道为非空的字符串,但是却出现以下异常:

From what I gather, the IronPython runtime is supposed to try and select the best overload based on the passed-in argument. In my case, I'm passing in a string which I know to be non-null, yet I get the following exception:

可以匹配多个目标:导航(Uri),导航(str)

Multiple targets could match: Navigate(Uri), Navigate(str)

看到我的论点很明显是一个字符串,为什么IronPython坚持认为多个目标可以匹配? System.String不会强制转换为System.Uri,因此第二种方法重载不应成为选择的可行选择...

Seeing as my argument is blatantly a string, why does IronPython insist that multiple targets could match? System.String does not cast to System.Uri and as such the second method overload should not be a viable candidate for selection...

推荐答案

听起来好像IronPython决定以某种方式将字符串转换为Uri.我不知道这也许是一个功能".您可以执行以下操作():

It sounds like somehow IronPython is deciding that it can convert strings to Uris. Perhaps this is a "feature", I don't know. You could do something like the following (source):

navigate_string = myObj.Navigate.Overloads[type("")]
navigate_string("asdf")

这篇关于在IronPython中访问.NET类方法重载时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆