开发者

Errors accessing .NET class method overloads in IronPython

I have a class I've written in C#. 开发者_如何学PythonThe class has two methods, the signatures being:

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

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:

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

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...


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")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜