I researched the use of a condition framework to verify data instead of
if(cond) throw new SomeException();
SomeFramework.MakeSure(cond);
In the end my choice is to use either the CodeContract
or CuttingEdge.Conditions
frameworks.
I can not decide which framework to use. I can tell you that what I don't like about the 'CodeContract' framework is that you have to install the extra msi
in order to use it and the options you need to choose; not that its bad, but it feels not natural. (And of course its still under MS research.)
What do you think?
The CodeContracts
framework is part of .NET 4. So you can write code against it without having to install anything, it's just that without the rewriter component the code contracts won't have any effect at runtime. I take this inclusion in the framework as a sign that Microsoft intends to integrate code contracts more in future.
According to the stats on the CuttingEdge.Conditions
CodePlex page, it's only been downloaded 4,189 times. There are some nice things about the syntax, but unless there is something specifically supported by CuttingEdge.Conditions
and not by CodeContracts
, you might as well stick with the version that's part of .NET.
The key features of code contracts, as far as I am concerned, are as follows:
You can set up code contracts on interfaces, to specify the expected behaviour of types implementing those interfaces.
Code contracts are inherited.
I haven't tried CuttingEdge.Conditions
, but it's not obvious that it supports these two features (whereas CodeContracts
does).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With