Skip to content
Discussion options

You must be logged in to vote

No interfaces can have a user defined operator to a type defined like this. THat's because the end (or subclass) type may truly implement htat interface). In which case, instead of the actual runtime check and downcast, it would go through this user case instead.

Consider this trivial example:

interface IFoo
{
}

class C
{
    public static implicit operator C(IFoo foo) => new C(...);
}

class D : C, IFoo
{
}

IFoo i = new D();
C c = (C)i; // this needs to not call through the conversion operator (which would create a new C), but instead actually just downcast properly.

Are there any plans to ease this limitation?

Unlikely. Casting interfaces to a base class only going through the runti…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@fitdev
Comment options

@CyrusNajmabadi
Comment options

Answer selected by fitdev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants