c# - Is it possible to provide a decendent class as a formal parameter in an overriden function and still compile -
what best way provide mechanism in base class can have function class parameter , decendant class can override function parameter decendant of base classes parameter. confused, let me construct implement below:
base class
public class basereportcontroller { private actionresult internalrenderreport(basereportmodel model) { reportexecution execution = this.getreportexecution(model); execution.addrequiredparameter("databasename", atargetdatabase); execution.addrequiredparameter("databaseservername", atargetserver); //send execution ssrs wrappers return report payload } public virtual reportexecution getreportexecution(basereportmodel model) { return null; } }
extended class
public class extendedreportcontroller:basereportcontroller { public override reportexecution getreportexecution(extendedfrombasereportmodel model) { reportexecution exec = new reportexecution(); exec.addoptionalparameter("someid1", model.someid1); exec.addoptionalparameter("someid2", model.someid2); return exec; } }
is there anonymous parameter allow me define extendedfrombasereportmodel
formal parameter in overridden method , still compile?
use base class , cast derived type inside method.
public class extendedreportcontroller:basereportcontroller { public override reportexecution getreportexecution(basereportmodel model) { var castedmodel = (extendedfrombasereportmodel) model; reportexecution exec = new reportexecution(); exec.addoptionalparameter("someid1", castedmodel.someid1); exec.addoptionalparameter("someid2", castedmodel.someid2); return exec; } }
Comments
Post a Comment