What is the best alternative for Code Contracts in

2020-06-07 07:36发布

问题:

I am looking to validate method parameters in my code, in the most elegant fashion possible. Code Contracts don't seem to work in 2015. Does anyone use any alternatives?

回答1:

They're working on it: https://github.com/Microsoft/CodeContracts/pull/36

If you cannot wait, there are a few things that you can do to fix this: https://github.com/Microsoft/CodeContracts/issues/18



回答2:

"The contract editor extensions now have a single VSIX package for all of the Visual Studio versions includign VS2015!"

https://visualstudiogallery.msdn.microsoft.com/1ec7db13-3363-46c9-851f-1ce455f66970



回答3:

I have installed CodeContracts v.1.10.10126.2-rc1 and it is working (and stable) with Visual Studio 2015.

This version of CodeContracts is the first major community-driven release of the DotNet CodeContracts. This release addresses a lot of pending issues with installer, new IL patterns introduced by Roslyn Csc compiler, etc..

NuGet package is located here: https://www.nuget.org/packages/DotNet.Contracts/1.10.10126.4

Prior to this version of CodeContracts, I had to turn contract checking off so I could get my applications to run in VS2015.