I need to implement the IDataErrorInfo interface in a base class. The interface requires a property and an indexer. I want to provide a default implementation for both and allow subclasses to override it. I can’t seem to wield the syntax for a ‘virtual’ implementation with the syntax for interface implementation! For example:
type ViewModelBase() =
interface IDataErrorInfo with
abstract Error : string with get
default this.Error with get() = ""
Gives the following compile errors
Error 1 Unexpected keyword ‘abstract’ in member definition. Expected
‘member’, ‘override’ or other
token. D:\MinorApps\VetCompass\VetCompass\ViewModel\ViewModelBase.fs 18 7 VetCompassError 2 Incomplete structured construct at or before this point in
pattern D:\MinorApps\VetCompass\VetCompass\ViewModel\ViewModelBase.fs 19 7 VetCompass
I’m not even sure where to begin with the indexer!
All interface implementations are explicit, which means that the methods of the interface will be private when viewed as members of the class. Thus, you can’t use the
abstractanddefaultmodifiers in the implementation. Instead, you’ll need to add a bit of duplication: