The official Fatica Labs Blog! RSS 2.0
# Thursday, March 15, 2012

I’ve already talked about the simple contract checking library here. I did a little improvement that allow us to write such a code:

public void DoSomethingWithCustomMessage(string arg1)
            Contract.Expect(() => arg1)
                .Throw<Exception>("I'm unhappy to see that {0} is null")


Note than {0} is replaced with the name of the argument so the library is refactoring friendly and DRY. The only restriction is that the exception type must support a constructor with a single string argument. Obviously .Throw can be used fluently after each all Expect(). As another minor improvement, even the .Expect can be called now fluently more than once, so multiple check can be done fluently too. The entire repository is on Bitbucket here. In order to use the library you just have to include the single file, but is better to point the repository since the file version can change in subsequent releases.

Thursday, March 15, 2012 4:16:42 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
C# | CodeProject

My Stack Overflow

Send mail to the author(s) E-mail

profile for Felice Pollano at Stack Overflow, Q&A for professional and enthusiast programmers
About the author/Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2021
Felice Pollano
Sign In
Total Posts: 157
This Year: 0
This Month: 0
This Week: 0
Comments: 140
This blog visits
All Content © 2021, Felice Pollano
DasBlog theme 'Business' created by Christoph De Baene (delarou) and modified by Felice Pollano