c# - Calling specific descendant of interface in an implementation of another interface -


i have interface iclass defined. 1 method in interface takes interface, iobject, argument.

in 1 specific implementation of iclass, need method take specific implementation of iobject, objectimplementation - c# tells me need implement method is.

why this? isn't objectimplementation instance of iobject? how around this? tried using abstract class instead , same mess.

public interface iclass {     bool somemethod(iobject object); }  public interface iobject {     ... // methods here }  public objectimplementation : iobject {     ... // method implementations here }  public classimplementation : iclass {     public bool somemethod(objectimplementation object) // <- c# compiler yells @ me     {      } } 

the contract states method requires iobject. objectimplementation one class implementing interface. there might others. contract of iclass states all implementations valid parameters.

if need constrain parameter objectimplementation consider using generic interface:

public interface iclass<t> t : iobject {     bool somemethod(t item); }  public classimplementation : iclass<objectimplementation> {     public bool somemethod(objectimplementation item)     {      } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -