Can't access interface method
I have an interface with a defined method - RegisterLanguageChange, but I can't use it in the class that implements the interface. Although I can use ChangeLanguageVersion. Why?
3 Replies
The main problem (aside from the visibilitiy) in your case is that you are using default interface implementations, which behave a bit different
You'd have to cast
this
to the actual interfaceCheck out https://andrewlock.net/understanding-default-interface-methods/#default-interface-methods-are-not-inherited for an explanation
Andrew Lock | .NET Escapades
Understanding C# 8 default interface methods
In this post I provide an introduction to default interface methods, how they work at a high level, their typical uses, and some of their sharp edges
Ideally, avoid implementation in interfaces. It was added as a tool to help with refactoring more than anything else, and should not be reached for as the default solution.