implicit operator using interfaces

The reason you can’t do this is because it is specifically forbidden in the C# language specification:

Source: ECMA-334 Section 15.10.4

A class or struct is permitted to
declare a conversion from a source
type S to a target type T provided all
of the following are true:

  • Neither S nor T is object or an interface-type.

and

User-defined conversions are not
allowed to convert from or to
interface-types. In particular, this
restriction ensures that no
user-defined transformations occur
when converting to an interface-type,
and that a conversion to an
interface-type succeeds only if the
object being converted actually
implements the specified
interface-type.

Leave a Comment