code-contracts

Code contracts. How suppress warnings on generated code?

只谈情不闲聊 提交于 2019-12-04 14:16:32
How can I turn off static checks on my Linq2Sql code? You can suppress checks on static code by marking the class(es) in question with [ContractVerification(false)] . If your generated classes are partial you can create another file with another part(ial) in it and add it there, so it doesn't get overwritten when the code is regenerated. 来源: https://stackoverflow.com/questions/3662293/code-contracts-how-suppress-warnings-on-generated-code

IOC Container Handling State Params in Non-Default Constructor

混江龙づ霸主 提交于 2019-12-04 13:23:55
问题 For the purpose of this discussion, there are two kinds of parameters an object constructor might take: state dependency or service dependency. Supplying a service dependency with an IOC container is easy: DI takes over. But in contrast, state dependencies are usually only known to the client. That is, the object requestor. It turns out that having a client supply the state params through an IOC Container is quite painful. I will show several different ways to do this, all of which have big

Microsoft Code Contracts and CI build server

泄露秘密 提交于 2019-12-04 07:31:45
问题 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? 回答1: Can I use code contract rewriting without

Code Contracts: How to deal with inherited interfaces?

柔情痞子 提交于 2019-12-04 05:21:28
I'm using MS Code Contracts and have run into a snag with using interface inheritance and ContractClassFor attributes. Given these interfaces and contract classes: [ContractClass(typeof(IOneContract))] interface IOne { } [ContractClass(typeof(ITwoContract))] interface ITwo : IOne { } [ContractClassFor(typeof(IOne))] abstract class IOneContract : IOne { } [ContractClassFor(typeof(ITwo))] abstract class ITwoContract : IOneContract, ITwo { } Let's say that IOne and ITwo are substantial interfaces. So IOneContract would have a significant amount of code in it for the necessary checks. I don't want

Code Contracts for mono?

流过昼夜 提交于 2019-12-04 03:48:56
Does mono support Code Contracts ? I.e. if I build a class library, can mono users use my assembly? If not, are there any alternative libraries? Preferably supporting static analysis (through a plugin or similar in visual studio) According to the compatability website , Monos Code Contracts API is done but the tooling is not yet complete. EDIT : The newest version of Mono (2.8) only supports Contract.Requires calls and you have to rewrite you code with ccrewrite, link . 来源: https://stackoverflow.com/questions/6483055/code-contracts-for-mono

How do I use code contracts in .NET 4.0 without making my code look cluttered?

只愿长相守 提交于 2019-12-04 03:45:21
I have started using Code Contracts and have found that it makes it difficult to immediately spot the 'guts' of a method. Take this (very simple) example: public static void UserAddNew(string domain, string username, string displayName) { Contract.Assert(!string.IsNullOrWhiteSpace(domain)); Contract.Assert(!string.IsNullOrWhiteSpace(username)); Contract.Assert(!string.IsNullOrWhiteSpace(displayName)); LinqDal.User.UserAddNew(domain, username, displayName); } Now I'm tempted to put the contracts in a region, so that they can be hidden away, but then I'm concerned that I'm losing a nice

Generate Contracts for REST objects

对着背影说爱祢 提交于 2019-12-04 02:48:59
I'm new to REST and this sounds like it should be pretty simple. In a .NET app, I can create a reference to a WCF service and the contracts for all the available types will be generated for me. Now I'm trying to consume a REST service in a Windows Phone 7 app. While I can make my call and get back the proper response, is there a simple way to create the classes that each object would be deserialized to? I'm using RestSharp to manage my calls. In some examples I've seen, user's have created their own classes, and generated the xml manually. I would like to avoid this if at all possible. many

Can I leave contracts in code that I'm merging with a codebase used by non-code contracts developers?

佐手、 提交于 2019-12-03 23:55:17
问题 For the last few months I've been developing a side project for my company, but the higher-ups have now decided it would be a good fit in an existing product. I've been developing the side project using Microsoft's Code Contracts for static type checking (partly because I hadn't used them before and was eager to learn). My problem is that if I check in my code to the code base with Contracts in place, will every other developer need the Code Contracts tools installed to be able to continue

Are code contracts guaranteed to be evaluated before chained constructors are called?

牧云@^-^@ 提交于 2019-12-03 12:53:27
问题 Before I started using Code Contracts I sometimes ran into fiddlyness relating to parameter validation when using constructor chaining. This is easiest to explain with a (contrived) example: class Test { public Test(int i) { if (i == 0) throw new ArgumentOutOfRangeException("i", i, "i can't be 0"); } public Test(string s): this(int.Parse(s)) { if (s == null) throw new ArgumentNullException("s"); } } I want the Test(string) constructor to chain the Test(int) constructor, and to do so I use int

Code Contracts + Code Analysis

跟風遠走 提交于 2019-12-03 12:02:36
问题 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