I talked about this one file utility here and here. I decided the syntax I create in the last improvement, for allowing the user to customize the exception to throw was not so usable, so I modified it. Now the resulting code to throw a specific exception is:
/// /// Classical not null verification, with custom /// exception and message /// /// public void DoSomethingWithCustomMessage(string arg1) { Contract.Expect(() => arg1) .Throw((n)=>new Exception(string.Format("I'm unhappy to see that {0} is null",n))) .WhenViolate .IsNotNull(); }
So there is no more any magic formatting, we just need to provide a function returning some kind of exception. The lambda argument (n) is the literal representing the name argument. I also added a wiki page on the project repository, to show the basic usage of the library so at a glance you can see how it works.
Remember Me
a@href@title, b, strike, strong
E-mail
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.