File size

File size

File size

File size

58.0 MB

Mike Barnett and Daryl Zuniga, a high school intern at RiSE, sit down to talk about Code
Contracts for .NET and documentation. Daryl has been working this summer on a tool that inserts contracts elements into the Xml Documentation files generated by the C#/VB compiler. Daryl also updated the Sandcastle
stylesheets so that the contracts appear in the documentation pages.

cool, but i agree, its good but the way its implemented it wont show up in intellisense.. you could perhaps have an options to paste in the comments in the summary/params element instead of as new elements

what i dont get is how the contracts are turned into expressions, Requires() just takes a bool, not Expression<bool> (right?) how does that work?

Does the the "green bubble" Daryl is working on serve your goal of seeing the contracts when you inherit? I am a bit unclear when/where the green bubble appears.

By the way, I'm glad Microsoft is hiring talented high school interns. I wish other business would give young people more chances like this. It's really important to their professional and personal growth.

Neither of those (Expression Trees or T4). Code Contracts use CCI (http://ccimetadata.codeplex.com ) to read the MSIL byte stream and decompile the expressions and rewrite the bodies to insert runtime checks.

You're exactly right, you can get them to show up by patching into the summary tag, in fact I've already got code for CCDoc that does just that. However, with VS2010 we can do even better, with some of their new extensibility features you can now add
additional information into an IntelliSense QuickInfo bubbles, however this won't be available until beta 2.

At dkallen:

You’re right, the "green bubble" is meant to help you when you're implementing an inherited method that has contracts so you know exactly what those contracts are. Our "green bubble" will only appear if you’re inheriting from an interface/class that
is in a compiled assembly (i.e. not in your current project) because the code contracts tools work by decompilation.

The CodeContracts tool chain builds its own "contracts" dll (i.e. filename.contracts.dll) that contains all the contracts information that CCDoc or other contract tools need and it must be present in order for them to work. This contracts dll is automatically
built if you check the "Build a Contract Reference Assembly" in your CodeContracts settings in VS (similar to the "Emit contracts into XML doc file" option I talked about in the film).

Yes, it's all done with MEF. You can't currently plug into the IntelliSense bubbles, but hopefully in beta 2 or so you will be able to

Yes, the idea is that the bubbles (adornments) should show up when you are writing an override of a virtual method in a supertype or an implementation of an interface method and you are going to inherit a contract from the overidden method or the interface
method (respectively). Otherwise you might not be aware of it.

But unfortunately, I am having some problems with this Xml Documentation from Code Contracts. I have taken the same steps as Daryl on this video, but I am not able to get the contract tags into the xml documentation file. I am using 1.2.21023.14 version
and tried it with both VS2008 and VS2010 Beta 2. There are no errors but simply contracts are not shown.

Remove this comment

Remove this thread

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums, or
Contact Us and let us know.