code-contracts

Does VS2017 work with CodeContracts?

夙愿已清 提交于 2019-11-27 09:58:05
问题 I just installed the newly released Visual Studio 2017 Enterprise (RC). However I'm having trouble getting it to work with Microsoft CodeContracts. I have no problem using CodeContract with VS2015 at all. Am I missing something? 回答1: As others have noted, Microsoft hasn't prioritized Code Contracts and its long-term support remains unclear (though there has been some ongoing discussion about language-level integration via Roslyn). As of March 11th, 2017, however, community contributor Yaakov

Using Contract.ForAll in Code Contracts

狂风中的少年 提交于 2019-11-27 05:54:29
问题 Okay, I have yet another Code Contracts question. I have a contract on an interface method that looks like this (other methods omitted for clarity): [ContractClassFor(typeof(IUnboundTagGroup))] public abstract class ContractForIUnboundTagGroup : IUnboundTagGroup { public IUnboundTagGroup[] GetAllGroups() { Contract.Ensures(Contract.Result<IUnboundTagGroup[]>() != null); Contract.Ensures(Contract.ForAll(Contract.Result<IUnboundTagGroup[]>(), g => g != null)); return null; } } I have code

Code Contracts: How do I supply a contract class for a generic interface?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 03:03:49
问题 I'd like to specify a contract for this generic interface, using Code Contracts: interface IRandomWriteAccessible<T> { T this[uint index] { set; } uint Length { get; } } The documentation says to use the ContractClass attribute when specifying a contract for an interface. However, the compiler will complain about this: [ContractClass(typeof(IRandomWriteAccessibleContract<T>))] // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <-- compiler error interface IRandomWriteAccessible<T> { … }

ReSharper - Possible Null Assignment when using Microsoft.Contracts

依然范特西╮ 提交于 2019-11-26 15:08:28
问题 Is there any way to indicate to ReSharper that a null reference won't occur because of Design-by-Contract Requires checking? For example, the following code will raise the warning ( Possible 'null' assignment to entity marked with 'NotNull' attribute ) in ReSharper on lines 7 and 8: private Dictionary<string, string> _Lookup = new Dictionary<string, string>(); public void Foo(string s) { Contract.Requires(!String.IsNullOrEmpty(s)); if (_Lookup.ContainsKey(s)) _Lookup.Remove(s); } What is