Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic parameter inference and ambiguous function call - is there a workaround? [duplicate]

Possible Duplicate:
Ambiguous call between two C# extension generic methods one where T:class and other where T:struct

I've this two functions :

public static Degrees Convert<TInput>(this TInput input)
  where TInput : NumericValue, IDegreesBased, new()
{
  //Some stuff
}

public static SquarredMeters Convert<TInput>(this TInput input)
  where TInput : NumericValue, ISquarredMetersBased, new()
{
  // Some stuff
}

When I call new SquarredKilometers(10).Convert(), there is an error saying that the call is ambiguous between the two functions above. The SquarredKilometers class implements the ISquarredMetersBased interface.

EDIT : So it seems to be normal. Any workaround for this precise problem ? (Interface implementation)

like image 876
Nicolas Voron Avatar asked Dec 04 '25 19:12

Nicolas Voron


1 Answers

Constraints are not part of the method signature, so the methods have identical parameter types. Eric Lippert always explains C# the best: http://blogs.msdn.com/b/ericlippert/archive/2009/12/10/constraints-are-not-part-of-the-signature.aspx

like image 151
erikkallen Avatar answered Dec 07 '25 15:12

erikkallen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!