code-contracts

JavaScript Code Contract Libraries?

南笙酒味 提交于 2019-12-20 09:19:29
问题 I am just starting up a new web application and I want to implement some form of contract'esque style validation in my JavaScript. I did some quick googling, and came across JsContact but the syntax isn't quite what I had in mind. Is anyone aware of other libraries? I am thinking I want the syntax to be something like String.prototype.padLeft = function(c, width) { Verify.value(c).isRequired().isNotNull().isChar(); Verify.value(width).isRequired().isNotNull().isNumber().greaterThan(0); ...

How do I include contract assemblies in the nupkg automatically?

空扰寡人 提交于 2019-12-19 09:46:20
问题 I just started using nuget to create some packages for an internal library in our company. This library is comprised of many assemblies, and a lot of them have contract reference assemblies generated from Code Contracts. I'm using the most straightforward nuget pack approach, which is to pass in the csproj file paths and let it resolve all dependencies between projects. The problem is that it does not include the contract assemblies in the lib folder. Is there a way to make it also get the

Books on Code Contracts in C# 4.0 [closed]

为君一笑 提交于 2019-12-19 08:31:00
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Altough I've known Code Contracts for some time, as I've used it a bit in Java, I would like to start using them in C#, now that they

CodeContracts: Boolean condition evaluates to a constant value, why?

筅森魡賤 提交于 2019-12-19 05:20:26
问题 I'm getting this warning but can't figure out the problem... CodeContracts: warning: The Boolean condition d1.Count != d2.Count always evaluates to a constant value. If it (or its negation) appear in the source code, you may have some dead code or redundant check The code is as follows: public static bool DictionaryEquals<TKey, TValue>(IDictionary<TKey, TValue> d1, IDictionary<TKey, TValue> d2) { if (d1 == d2) return true; if (d1 == null || d2 == null) return false; if (d1.Count != d2.Count)

How to find 'masked' assertions in MS Code Contracts

↘锁芯ラ 提交于 2019-12-18 15:01:19
问题 I have the following Message-level entry in my Error List from CodeContracts: CodeContracts: Checked 410 assertions: 404 correct (6 masked) I can't figure out: What masked assertions are How to locate the 6 that it mentions Whether or not I should be concerned about them Sorry for not posting code... I have no idea how to recreate this in a small sample :) Many thanks 回答1: It's simple, in your project properties>Code Contracts>Static Checking> put the warning at "hi". Now ccCheck made more

Why is ccrewrite.exe not doing anything from the command line?

亡梦爱人 提交于 2019-12-18 03:49:09
问题 I've got Code Contracts working fine from inside Visual Studio 2010, but I can't get ccrewrite.exe to do anything useful from the command line. Here's a sample app: using System.Diagnostics.Contracts; public class Dummy { public static void Main(string[] args) { Contract.Requires(args.Length > 0); } } I then compile the code and run ccrewrite.exe on it: > csc /debug+ /D:CONTRACTS_FULL Dummy.cs > ccrewrite /o:RewrittenDummy.exe Dummy.exe elapsed time: 61ms There's no RewrittenDummy.exe file

.NET Guard Class Library?

时间秒杀一切 提交于 2019-12-17 22:35:47
问题 I'm looking for a library or source code that provides guard methods such as checking for null arguments. Obviously this is rather simple to build, but I'm wondering if there are any out there for .NET already. A basic Google search didn't reveal much. 回答1: There is CuttingEdge.Conditions. Usage example from the page: public ICollection GetData(Nullable<int> id, string xml, ICollection col) { // Check all preconditions: id.Requires("id") .IsNotNull() // throws ArgumentNullException on failure

Combining code contracts and regex

梦想与她 提交于 2019-12-14 00:35:45
问题 So I have a very simple class with one string as property. This string has to have a certain pattern. I'm trying to enforce this using code contracts. The class looks something like this: class SimpleClass { public Property { get; set; } public SimpleClass(string prop) { Contract.Requires(IsValid(prop)); this.Property = prop; } [ContractInvariantMethod] void ObjectInvariant() { Contract.Invariant(IsValid(Property)); } bool IsValid(string arg) { // Use regex to check if arg is a valid string }

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

廉价感情. 提交于 2019-12-14 00:19:40
问题 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

Should CodeContracts replace the regular ArgumentExceptions?

北慕城南 提交于 2019-12-12 14:44:24
问题 Could I start using CodeContracts instead of: if (XXX == Y) throw new ArgumentException("bla bla"); How does it work if I develop a library and my library users do not use CodeContracts? 回答1: Assuming that the code using code contracts is run through the binary rewriter, it will throw exceptions like code you posted. The re-writer goes through the code and replaces the contract code with argument checking etc. It's kinda like aspect oriented programming. It injects code to handle situations