I never thought I’d have a need for anything this (since macros are bad, right?), but it turns out I do.
I find myself repeating the following pattern over and over again in my code, dozens if not hundreds of times:
object Function() {
this.Blah = this.Blah.Resolve(...);
if(this.Blah == null)
return null;
if(this.Blah.SomeFlag)
return this.OtherFunction();
// otherwise, continue processing...
}
I’d like to write something like this instead:
object Function() {
this.Blah = this.Blah.Resolve(...);
VerifyResolve(this.Blah);
// continue processing...
}
Except the fact that the pattern contains conditional returns means I can’t factor out a function. I’ve had to subtly change the pattern once already, and since I couldn’t do a simple search it was a pain to find all the instances.
How can I avoid repeating myself needlessly, and make any future changes to this pattern easier?
You could say something like: