I have class / interface definitions in C #
public class FooBase {
...
protected bool Bar() { ... }
...
}
public interface IBar {
bool Bar();
}
Now I want to create a class Foo1 derived from FooBase that implements IBar:
public class Foo1 : FooBase, IBar {
}
Is there any class declaration mask that the compiler uses the inherited protected method as a public implementation of the interface?
Of course method foo1
bool IBar.Bar()
{
return base.Bar();
}
working. I'm just wondering if there is a shortcut;)
Omitting this method leads to a compiler error: Foo1 does not implement the IBar.Bar () interface member. FooBase.Bar () is either static, not public, or has the wrong return type.
Explanation: I separate code inheritance (class hierarchy) and function implementation (interfaces). Thus, for classes that implement the same interface, access to a common (inherited) code is very convenient.