I have the following implicit conversion operator:
public static implicit operator InputArgument<T>(T value)
{
return new InputArgument<T>(value);
}
The following is code in an ASP.NET MVC controller:
This works:
InputArgument<string> input = "Something";
This works:
InputArgument<Controller> input = this;
This works:
InputArgument<IPrincipal> input = new InputArgument<IPrincipal>(User);
But this doesn't work:
InputArgument<IPrincipal> input = User;
The last example gives the error:
> Cannot implicitly convert type
> 'System.Security.Principal.IPrincipal' to
> 'Engine.InputArgument<System.Security.Principal.IPrincipal>'. An
> explicit conversion exists (are you missing a cast?)
What could be the reason that this implicit conversion does not work for IPrincipal?
User-defined conversions are specified as not working on interfaces. If they did work on interfaces like this then you could end up in a situation where Bar<IFoo> is converted to IFoo via a representation-changing user-defined conversion when the object actually implements IFoo, which would be surprising.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With