Skip to content

Invoking default interface method implementation from a selected interface #14127

@damirarh

Description

@damirarh

Let's say I have the following rather contrived scenario:

interface I0
{
    string Method()
    {
        return "I0";
    }
}

interface I1 : I0
{
    string I0.Method()
    {
        return "I1";
    }
}

interface I2 : I0
{
    string I0.Method()
    {
        return "I2";
    }
}

Now I want a class to implement both I1 and I2:

class C12 : I1, I2
{
}

As expected, I get the following compiler error:

> Interface member 'I0.Method()' does not have a most specific implementation. Neither 'I1.I0.Method()', nor 'I2.I0.Method()' are most specific.

I can resolve this if I provide my own implementation. Inside it, how could I invoke the implementation from one of the interfaces, e.g. I1? I'm pretty sure the following syntax used to work in a previous preview:

class C12 : I1, I2
{
    string I0.Method()
    {
        return base(I1).Method();
    }
}

However, now the compiler complains:

> Use of keyword 'base' is not valid in this context

What is the correct syntax to invoke the default method implementation in interface I1? I can't find it documented anywhere.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions