I want to create a structure of Services all of them derived from the interface IService which has an only method Perform
In order to allow the derived classes to define the kind of arguments the specific Perform implementations need I encapsulate such arguments in an interface called IConfig
The problem is that I can not access to the derived class properties in my custom Perform implementations because I am forced to type the argument as IConfig
Is there any way I can override an interface/abstract class method with arguments of derived class of the interface's method's argument's class?
Example:
interface IConfig {} class Config : IConfig { public int Property; } interface IService { void Perform(IConfig config); } class Service : IService { void IService.Perform(IConfig config) { config.Property; } } With the above Service implementation I get the error:
'IConfig' does not contain a definition for 'Property'
If I change it to this:
class Service : IService { void IService.Perform(Config config) { config.Property; } } I get the errors:
'Service' does not implement interface member 'IService.Perform(IConfig)'
and
'Service.Perform(Config)' in explicit interface declaration is not found among members of the interface that can be implemented
I am wondering if there is something like:
void IService.Perform((IConfig)Config config) or
void IService.Perform(Config config as IConfig) or
(Config)config.Property
IConfighave different PropertiesIConfigand not overConfigreferences? The whole point of holding references to an interface is that your code doesn't need to know the implementation details.