I have an interface called IStructuredReader that reads some structured data from a file and displays it in a form. It has a member called Sync() , which, when implemented, validates the data for a user-defined data template.
Some implementations of IStructuredReader do not have synchronization capabilities. These implementations throw a NotImplementedException for the Sync() method. I would like to be able to check if this method is implemented so that I can mute the button in the form if it is not.
I can come up with several ways in which this could be done, all of which seem awkward and complex:
Separate the Sync method into your own interface, inherit it for those implementations that support this feature, and try passing the reader object to it to identify this feature,
Write NotImplementedAttribute , decorate it with a member and check for the presence of the attribute using Reflection,
Add the boolean HasSyncCapability boolean to the interface.
Is there a canonical way to do this?
source share