Displays Code Contracts (when editing C#) in code, Intellisense, and in metadata files.
Inheritance:
Displays contract information on methods with inherited contract information, or on interface/abstract methods
Metadata:
Displays contract information in metadata files.
Qui...
Great extension! I especially like the adornments for inherited contracts; a very nice addition.
The IntelliSense output is clobbered by ReSharper unless ReSharper's IntelliSense is disabled. That's unfortunate, but it's no fault of this extension.
EDIT [Possible Bug]: It seems that when defining contracts on an interface method that takes a reference to an interface in the Microsoft.Office.Interop.* namespace as a parameter, the extension does not show adornments for implementing types, nor does the hover text reflect the contract. See [http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/dda8fd5a-7a6d-44cb-bea9-dd11549acb61] and [http://stackoverflow.com/questions/9102059/issue-with-code-contracts-on-generic-interface].
In solution with 48 projects (C# and C++) compilation is not possible any more when the "Code Contracts Editor Extensions" is installed. VS2010 Professional (4.0.30319) hangs (CPU 100%, a lot MSBuild processes are spawned) while compiling the first C++ project. Disabling the extension doesn't help, only uninstalling it. It's a pity, because I like to see the code contract information in the tool tips.
This could eventually turn out to be a great extension, but I have several major grievances with it: - It's very slow, so contracts do not appear right when you open a file. It affects basic stuff like typing in editor windows by slowing them down - sometimes the added lag is so bad you can see characters appear way after you typed them (and this is on a modern PC). - The way contracts are displayed consumes too much horizontal space for my taste. It would be better if they appeared collapsed somewhere and only displayed on mouse-over, which may also allow for snappier operation as it wouldn't have to get all contracts at once. - There are various annoying visual glitches in the current release. I'll be keeping my eyes on future releases for now it's a pass from me.
When it works, it's very cool. Many times, it just does not work. And it slows down other operations, so I disabled it at work as I need high speed. But this is a great first release. I will keep it on at home for training and small stuff.
There seemed to be no such topic at connect so I've added one: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3330248-provide-code-constracts-editor-extension-for-vs201
Please vote!
I use GlobalAssemblyInfo.cs in my projects and the extension can't get assembly identity. So I have no intellisense on my contracts.
Output:
Getting the assembly identity for project...
Couldn't gather suffecient information from the project to construct an assembly identity.
A proper assembly identity could not be constructed, unable to reload assembly.
Assembly identity for the project: ... was null.
Failed to build assembly reference for: ...
Failed to get CCI reference for: ...
If I move assembly version from Global to AssemblyInfo.cs, then it works. Latest version of the Code Contract library and of the extension, VS 2010 Pro. Is there any way to fix it?
The extension works great, but I'm not getting intellisense support for constructors at all. Example of what I'm talking about follows. I have intellisense support on foo's go method, but not on the constructor.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace CodeContractsTest
{
class Program
{
static void Main(string[] args)
{
ConsoleWriter Foo = new ConsoleWriter("Bob");
Foo.Go();
Console.ReadLine();
}
}
public class ConsoleWriter
{
string _text;
public ConsoleWriter(string text)
{
Contract.Requires(text != null, "null isn't allowed!");
_text = text;
}
public void Go()
{
Contract.Ensures(_text != null, "text can't be null!");
Console.WriteLine(_text);
_text = null;
}
[ContractInvariantMethod]
void ObjectInvariant() {
Contract.Invariant(_text != null);
}
}
}
When I define a contract on an interface method that takes a reference to a type in Microsoft.Office.Interop.* as a parameter, adornments are not displayed on the interface definition or implementing types, and the hover text does not reflect the contract. Replacing the interop type with some other reference type resolves the issue.
Code Contracts DevLab Forum post: [http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/dda8fd5a-7a6d-44cb-bea9-dd11549acb61]
StackOverflow Post: [http://stackoverflow.com/questions/9102059/issue-with-code-contracts-on-generic-interface]
Still a great extension!
any way this will work with portable class libraries? i tried using reflector to copy the public 3.5 assemblies into a new PCL library, but that doesn't seem to help (i can reference the Contract class now, but the analysis doesn't seem to do anything)
I tried to install the extensions on Windows XP Professional German but i get an
Install Error : System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.