Code Contracts' static analyzer is a great feature, but of course it does have its limitations. Some things it just cannot check at compile-time, and other things it can… but doesn't (always).
One example of where the static analyzer could check, but doesn't, is on attribute contracts.
Say you define an attribute with code contracts in it, like so:
using System;
using System.Diagnostics.Contracts;
namespace CodeContractsTest
{
///
/// My super validation attribute.
///
public class SuperValidationAttribute : Attribute
{
public SuperValidationAttribute(string pattern)
{
Contract.Requires(!string.IsNullOrEmpty(pattern));
Contract.Requires(pattern.Contains("$"));
Pattern = pattern;
}
///
/// Gets or sets the pattern to use.
///
public string Pattern { get; set; }
}
}
Then when you use that attribute, the contracts will not be statically checked; i.e., if you use the attribute wrongly, you will not be warned at compile-time.
Microsoft is aware of this issue, and hopefully it will be fixed in an update soon.