code-contracts

How mature is the Microsoft Code Contracts framework?

允我心安 提交于 2019-12-03 02:13:03
问题 Microsoft has recently put a release of their Code Contracts framework on DevLabs with a commercial license. We're interested on using them in our project (mostly C#, some C++/CLI) to gradually replace all the custom validation code, but I'm keen to know about the experience other people have had with it before we commit to it, specifically: Do you think the framework is sufficiently mature for large and complex commercial projects? What problems have you run into while using it? What

Code Contracts + Code Analysis

邮差的信 提交于 2019-12-03 01:31:23
I think about starting to use Code Contracts in my code base. I already use Code Analysis with all rules enabled and a goal of zero warnings. However, when using Contract.Requires(parameter != null) I get a warning from Code Analysis, namely CA1062: CA1062 : Microsoft.Design : In externally visible method 'Foo', validate parameter 'parameter' before using it. That's unfortunate, I don't want to disable that rule as I find it useful. But I also don't want to suppress every false occurrence of it. Is there a solution? As of Version 4.5.2 of the framework (possibly even 4.5) it is possible to

What is a practical usage of Code Contracts in .NET 4.0?

倖福魔咒の 提交于 2019-12-02 21:47:50
In order to fully understand and take advantage of the new features and enhancements provided with the coming of the new .NET Framework 4.0, I would like to get an example of real-world application of Code Contracts . Anyone has a good example of application of this feature? I would like to get a code sample with a brief explanation to help me get up and running with it. From The Code Contracts User Manual : Contracts allow you to express preconditions, postconditions and object invariants in your code for runtime checking, static analysis, and documentation. Code Contracts are used for static

How to properly use Code Contracts in .NET Core

只谈情不闲聊 提交于 2019-12-02 20:22:56
I wonder, how to properly use Code Contracts in .NET Core , so far I tried to add CC to my project, compile and debug. I'm confused by message, which is appearing in each call which uses Contract.Requires , and information found by googling. The message states: An assembly must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.Requires<TException> and CONTRACTS_FULL symbol is defined. Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild. CCRewrite .... As I can see there are no CC options in the project

Usefulness of System.Diagnostics.Contracts in question

て烟熏妆下的殇ゞ 提交于 2019-12-02 18:02:10
I've been playing with the new System.Diagnostics.Contracts class because it seemed very useful at first. Static methods to check inbound arguments, return values, etc. It was a clean interface and could replace lots of if-then statements and internally built library tools. However, it seems less than useful in most runtime situations. From what I can tell, it doesn't throw an error so I can't catch anything to know if a contract failed. It pops up a dialog box with the error. If I'm running a wcf service on a remote box that rarely has a human look at it...how would I know the contract failed

Code contracts build reference assembly actions

白昼怎懂夜的黑 提交于 2019-12-02 17:57:51
I am using code contracts and trying to understand which of the build options shall I use and when. The contract assembly build options are defined in project properties Code Contracts -> Contract Reference Assembly : None Build DoNotBuild Any thoughts or recommendations? Yes, the None and DoNotBuild options seem a bit strange. If you select None and reference the library in a Project with contracts, you will get a Warning. If you select DoNotBuild you won't get a warning. And of course only Build produces a reference assy, and for a .EXE it all doesn't matter. The Contract Reference Assembly

How mature is the Microsoft Code Contracts framework?

旧巷老猫 提交于 2019-12-02 15:46:42
Microsoft has recently put a release of their Code Contracts framework on DevLabs with a commercial license. We're interested on using them in our project (mostly C#, some C++/CLI) to gradually replace all the custom validation code, but I'm keen to know about the experience other people have had with it before we commit to it, specifically: Do you think the framework is sufficiently mature for large and complex commercial projects? What problems have you run into while using it? What benefits have you got from it? Is it currently more pain than it's worth? I realise that this is a somewhat

Microsoft Code Contracts and CI build server

馋奶兔 提交于 2019-12-02 14:14:58
We are migrating to .NET 4 and very interested in implementing new Design By Contract capabilities. As we know Code Contract engine requires installation of Code Contract addin and VS Ultimate or Premium (for static checking). Here is my questions: Can I use code contract rewriting without installing VS on CI build Server (TeamCity)? Is there any msbuild tasks to execute Contract checking? Do you use Code Contract's validation with CI builds? Judah Gabriel Himango Can I use code contract rewriting without installing VS on CI build server (TeamCity)? Yes. Install CodeContracts on the build

Customising Code Contract Exception Messages

流过昼夜 提交于 2019-12-02 01:37:58
问题 I have a code contract expresses as this - it validates that entity to be stored is not null and is valid for persistence. It works. Fab. [ContractClassFor(typeof(IRepository<,>))] internal abstract class ContractsForIRepository<T, TId> : IRepository<T, TId> where T : IEntity { private ContractsForIRepository() { } public T Persist(T entity) { Contract.Requires<InvalidEntityException>(entity != null, "Entity is null"); Contract.Requires<InvalidEntityException>(entity.IsValidForPersistence(),

Code contracts for .NET 3.5 messes up VS10's debugger

六月ゝ 毕业季﹏ 提交于 2019-12-01 16:02:25
问题 I've recently migrated a lot of manual precondition testing and exception throwing with code contracts. Instead of upgrading to .NET 4, I've been using the Microsoft.Contracts.dll assembly so I could stick to .NET 3.5 a bit longer (this is a library that is used both by .NET 3.5 and .NET 4 assemblies). I've set up the contracts rewriter in Visual Studio 2010 and the contracts work just fine. However, since I've done that switch, I've noticed that the debugger acts funny in methods with