microsoft-contracts

Microsoft.Contracts namespace

▼魔方 西西 提交于 2020-01-05 04:58:11
问题 For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts; ? 回答1: For using code contracts. 回答2: You can find the library here C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll 来源: https://stackoverflow.com/questions/1679392/microsoft-contracts-namespace

Design by Contract: Can you have an Interface with a Protocol?

巧了我就是萌 提交于 2019-12-11 09:51:04
问题 I'm pretty new to the concept of Design by Contract, but so far, I'm loving how easy it makes it to find potential bugs. However, I've been working with the Microsoft.Contracts library (which is pretty great,) and I have run into a road block. Take this simplified example of what I'm trying to do: public enum State { NotReady, Ready } [ContractClass(typeof(IPluginContract))] public interface IPlugin { State State { get; } void Reset(); void Prepare(); void Run(); } [ContractClassFor(typeof

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

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

.NET 4.0 code contracts - How will they affect unit testing?

痞子三分冷 提交于 2019-11-30 05:38:25
For example this article introduces them. What is the benefit? Static analysis seems cool but at the same time it would prevent the ability to pass null as a parameter in unit test. (if you followed the example in the article that is) While on the topic of unit testing - given how things are now surely there is no point for code contracts if you already practice automated testing? Update Having played with Code Contracts I'm a little disappointed. For example, based on the code in the accepted answer: public double CalculateTotal(Order order) { Contract.Requires(order != null); Contract

.NET 4.0 code contracts - How will they affect unit testing?

人走茶凉 提交于 2019-11-29 04:38:28
问题 For example this article introduces them. What is the benefit? Static analysis seems cool but at the same time it would prevent the ability to pass null as a parameter in unit test. (if you followed the example in the article that is) While on the topic of unit testing - given how things are now surely there is no point for code contracts if you already practice automated testing? Update Having played with Code Contracts I'm a little disappointed. For example, based on the code in the

C#: Code Contracts vs. normal parameter validation

北战南征 提交于 2019-11-29 00:27:24
问题 consider the following two pieces of code: public static Time Parse(string value) { string regXExpres = "^([0-9]|[0-1][0-9]|2[0-3]):([0-9]|[0-5][0-9])$|^24:(0|00)$"; Contract.Requires(value != null); Contract.Requires(new Regex(regXExpres).IsMatch(value)); string[] tokens = value.Split(':'); int hour = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture); int minute = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture); return new Time(hour, minute); } and public static Time Parse

ReSharper - Possible Null Assignment when using Microsoft.Contracts

笑着哭i 提交于 2019-11-27 10:19:47
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 really odd is that if you remove the Contract.Requires(...) line, the ReSharper message goes away. Update I

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