I have two classes declared in C# code:
public class A
{
public static bool TryParse(string value, out A result)
{
...
}
}
public class B : A
{
public static bool TryParse(string value, out B result)
{
...
}
}
While calling B.TryParse from C# isn’t problem, because correct overload is determined by out parameter type, which should be declared in advance. As out parameter is transformet to part of result in F#, we got two function with same parameter signature… And call from F# causes A unique overload for method 'TryParse' could not be determined based on type information prior to this program point. A type annotation may be needed. error. I understand the issue, and would even declare TryParse as new… If it weren’t static.
The message itself is not very helpful: it’s absolutely not cleare what kind of annotation and where to add.
How can I do this call?
Most stupid idea is to rename one of functions, but may be there are more clever way?
You need to add a type annotation to the variables you are passing to the try method, in this case the out variable as this is the thing that changes. I think something like this should work:
In F# type annotations come after the an identifier and are preceded by a colon (:).
(Note: in F# out parameters can be recovered as tuple from the result)