Search code examples
c#.net.net-4.0c#-4.0contracts

Is all of .NET updated to use Contracts?


Since the introduction of Contracts to .NET 4.0, I am wondering if Microsoft propagated this to all of their classes like in the BCL?

If not, then why? This kind of feature only makes sense if it's supported in the standard library by default, right?


Solution

  • No Code Contracts have not been added to all of the BCL. Many of the most common classes have added the annotation but the whole of the BCL has not.

    The primary reason here is time. The BCL is huge and adding correct Contracts to all of the BCL is a massive undertaking. And the result, at this time, only benefits a small subset of the .Net user base. If Contracts grow in popularity then I'm sure their usage within the BCL will likewise grow (yes I realize not doing one makes the other less likely)

    This problem is mitigated though by the ability for users to declare custom Contract assemblies. This allows them to post-annotate types which were missed and get to a point where their code base is clean from a Contracts point of view.