I have a multi-level class hierarchy with a Refresh
method where each level introduces some new fields to be refreshed. In other words, I want the "level 3" class to refresh the fields of levels 1, 2 and 3, and the "level 4" class to refresh that of levels 1, 2, 3 and 4.
The basic solution is that each Refresh
method calls base.Refresh
. But I find this to be easy to overlook. I wish there was a way to annotate the root Refresh
declaration to say that I want "constructor-like base call logic" on that method, i.e, please insert a call to base.Refresh
before my method body for all children of that hierarchy. (If I can choose between pre and post-body i.e destructor-like, that's even better).
As far as I know there's no such thing in the base language, but I figure it's a common issue so perhaps some library introduces C# annotations that allow doing just that, as in the answer to Enforce super call on non constructor methods, or some suitable alternative. Is there ?