1. Felice Pollano
  2. NContracts

Commits

Felice Pollano  committed f845c2d

Edited online

  • Participants
  • Parent commits b962f68
  • Branches default

Comments (0)

Files changed (1)

File Home.wiki

View file
  • Ignore whitespace
 == Welcome ==
 
-Welcome to your wiki! This is the default page we've installed for your convenience. Go ahead and edit it.
+NContract is a library to help writing argument verifications check and trhrow logic without having to specify the argument name as a literal string.
+Let's see an example showing how to use it:
+{{{
+#!c#
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
 
-=== Wiki features ===
+namespace NContracts
+{
+    public class Demo
+    {
+        /// <summary>
+        /// Classical not null verification
+        /// </summary>
+        /// <param name="arg1"></param>
+        public void DoSomething(string arg1)
+        {
+            Contract.Expect(() => arg1).IsNotNull();
+        }
 
-This wiki uses the [[http://www.wikicreole.org/|Creole]] syntax, and is fully compatible with the 1.0 specification.
+        /// <summary>
+        /// Classical not null verification, with custom 
+        /// exception and message
+        /// </summary>
+        /// <param name="arg1"></param>
+        public void DoSomethingWithCustomMessage(string arg1)
+        {
+            Contract.Expect(() => arg1)
+                .Throw((n)=>new Exception(string.Format("I'm unhappy to see that {0} is null",n)))
+                .WhenViolate
+                .IsNotNull();
+        }
 
-The wiki itself is actually a mercurial repository, which means you can clone it, edit it locally/offline, add images or any other file type, and push it back to us. It will be live immediately.
-
-Go ahead and try:
-
-{{{
-$ hg clone https://bitbucket.org/Felice_Pollano/ncontracts/wiki
+        /// <summary>
+        /// Asserting an argument greather than another
+        /// </summary>
+        /// <param name="min"></param>
+        /// <param name="max"></param>
+        public void DoSomething(int min,int max)
+        {
+            Contract.Expect(() => min)
+                .IsLessThan(int.MaxValue)
+                .Meet(a => a <= max);
+        }
+        /// <summary>
+        /// Validate an integer argument in a certain range
+        /// </summary>
+        /// <param name="arg1"></param>
+        public void DoSomething(int arg1)
+        {
+            Contract.Expect(() => arg1).IsGreatherThan(0)
+                                       .IsLessThan(100);
+                ;
+           
+        }
+        /// <summary>
+        /// Validate an array in length and asserts first element should be zero
+        /// </summary>
+        /// <param name="array"></param>
+        public void DoSomething(int[] array)
+        {
+            Contract.Expect(() => array).Meet(a => a.Length > 0 && a.First() == 0);
+        }
+       
+    }
+}
 }}}
 
-Wiki pages are normal files, with the .wiki extension. You can edit them locally, as well as creating new ones.
 
-=== Syntax highlighting ===
-
-You can also highlight snippets of text, we use the excellent [[http://www.pygments.org/|Pygments]] library.
-
-Here's an example of some Python code:
-
-{{{
-#!python
-
-def wiki_rocks(text):
-    formatter = lambda t: "funky"+t
-    return formatter(text)
-}}}
-
-You can check out the source of this page to see how that's done, and make sure to bookmark [[http://pygments.org/docs/lexers/|the vast library of Pygment lexers]], we accept the 'short name' or the 'mimetype' of anything in there.
-
-Have fun!