c# - Returning in a base class's method returns in child class call? -
c# - Returning in a base class's method returns in child class call? -
i'm creating c# framework in (nearly) of classes based off of single, abstract base of operations class. base of operations class contains privately-set properties, 1 of beingness boolean garbage.
in xna's draw loop, don't want kid classes execute code in respective draw() methods if base of operations class's garbage property set true. tried doing next implementation:
abstract base of operations class:
class="lang-cs prettyprint-override">public virtual void draw(gametime gametime, spritebatch spritebatch) { if (garbage) return; }
inherited class:
class="lang-cs prettyprint-override">public void draw(gametime gametime, spritebatch spritebatch, color overlaycolor, float scale) { base.draw(gametime, spritebatch); //other code here... }
because base of operations class's draw method beingness called before actual code in kid class, hits return statement, want follow through kid class's draw() call. however, isn't happening.
is there way accomplish effect want, without adding "if (garbage) return;" restriction top of every inherited class's draw() method?
one thing might consider have 2 methods. have draw method on abstract base, not overridden, , define abstract protected method called performdraw() inheritors override.
abstract base of operations draw looks like:
public void draw(gametime gametime, spritebatch spritebatch) { if (!garbage) performdraw(gametime, spritebatch); }
this lets override draw behavior forces inheritors utilize "garbage" check.
c# inheritance xna return base
Comments
Post a Comment