Well, it may be a bit of a hack, but carry with me :) The background is that I'm tired of the methods, which some if-statements will interfere with the indentation for the whole method, for example:
public SomeClass DoStuff(string inputStr) { SomeClass result =null; if (IsOpenFilter(inputStr)) { .... } return result; }
So, I was wondering if this would be tidy if I could do something like this:
public SomeClass DoStuff(string inputStr) { Require(IsOpenFilter(inputStr),null); .... return result; }
This case may be covered by code contracts in one form or another, if so, please correct me :)
The idea is that if the operator does not evaluate true, it returns null. If there was no return type for the method, it would be simple: Require (IsOpenFilter (inputStr));
So, I think there are two questions, can this be somehow done? I do not understand how to make a conditional return from a method call.
Another question: is this a good idea? It's a little strange when monkeypatch is in this language, but I would like the code to read. I would be even cleaner if it could be added to the attribute above the method: [Require (IsOpenFilter (inputStr))]
source share