design-by-contract

'Design By Contract' in C#

て烟熏妆下的殇ゞ 提交于 2019-11-27 05:05:14
问题 I wanted to try a little design by contract in my latest C# application and wanted to have syntax akin to: public string Foo() { set { Assert.IsNotNull(value); Assert.IsTrue(value.Contains("bar")); _foo = value; } } I know I can get static methods like this from a unit test framework, but I wanted to know if something like this was already built-in to the language or if there was already some kind of framework floating around. I can write my own Assert functions, just don't want to reinvent

api documentation and “value limits”: do they match?

对着背影说爱祢 提交于 2019-11-27 04:51:15
问题 Do you often see in API documentation (as in 'javadoc of public functions' for example) the description of "value limits" as well as the classic documentation ? Note: I am not talking about comments within the code By "value limits", I mean: does a parameter can support a null value (or an empty String, or...) ? does a 'return value' can be null or is guaranteed to never be null (or can be "empty", or...) ? Sample: What I often see (without having access to source code) is: /** * Get all

Design by contract using assertions or exceptions? [closed]

喜夏-厌秋 提交于 2019-11-26 17:26:22
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . When programming by contract a function or method first checks whether its preconditions are fulfilled, before starting to work on its responsibilities, right? The two most prominent ways to do these checks are by assert and by exception . assert fails only in debug mode. To

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