Scott Dorman

ephemeral segment

  Home  |   Contact  |   Syndication    |   Login
  570 Posts | 10 Stories | 639 Comments | 51 Trackbacks

News


Post Categories

Image Galleries



Creative Commons License


Microsoft MVP


MCP Profile


Locations of visitors to this page

Subscribers to this feed

TwitterCounter for @sdorman

View blog authority

Add to Technorati Favorites

Windows Live Alerts

AddThis Social Bookmark Button

LinkedIn profile

Community Credit profile

The Code Project

Follow me on Twitter

Get Free Shots from Snap.com

Community Credit Hall of Fame

Get Feedghost

Xobni outlook add-in for your inbox

Windows Live Translator


Support This Site

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Last month I talked about Code Contracts, which are one of the new features in .NET 4.0. Earlier today I was digging around in .NET Reflector looking for something totally unrelated when I came across the Microsoft.Contracts namespace in System.Core.

image

Looking at the Contract class reveals some custom exception types and a bunch of static methods that look surprisingly similar to what will be available in the CodeContract class in .NET 4.0.

What does this mean? It means that Microsoft internally was already using code contracts in .NET 3.5 but they weren’t available to the rest of us.

If you recall from my previous post, I mentioned that the CodeContract support in .NET 4.0 was based on the work done in Spec#. Looking at the disassembly of the Contracts class, specifically any of the methods that represent a post-condition evaluation, reveals a System.Diagnostics.ConditionalAttribute declaration with a value of “USE_SPECSHARP_ASSEMBLY_REWRITER”.

image

This attribute very clearly indicates that the code contract portions of Spec# had already made their way in to the .NET Framework with version 3.5. Not only that, but using the analyzer capabilities of Reflector show that the Contract class is being used by some of the Microsoft.Win32.SafeHandles and System.Security.Cryptography classes.

Running Reflector against the .NET 4.0 CTP reveals that the CodeContract class is very similar to the Contract class. It turns out that not only do all of the places that previously used the internal Contract class now use the new CodeContract class but a lot of new classes use it as well (including System.AddIn). The old Contract class is still present, but no longer used.

A few differences are that the new CodeContract class has more methods available and the Conditional attribute appears to have changed from USE_SPECSHARP_ASSEMBLY_REWRITER to CONTRACTS_PRECONDITIONS and CONTRACTS_FULL Conditional attributes.

The other important thing to realize is that the Assert and Assume methods are also marked with a DEBUG conditional which means that they will only appear in debug builds.

 

Technorati Tags: , ,
DotNetKicks Image
posted on Wednesday, December 10, 2008 1:36 PM