Solved

System.Diagnostics.Contracts

Posted on 2011-09-15
1
291 Views
Last Modified: 2012-05-12
I am using .net 4, but I could not find this dll.
And what is the function of it?
// ----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics.Contracts;

namespace ContractsDemo
{
    [ContractVerification(true)]
    class Program
    {
        static void Main(string[] args)
        {
                var password = GetPassword(-1);
                Console.WriteLine(password.Length);
            

            Console.ReadKey();
        }

        #region Header
        /// <param name="userId">Should be greater than 0</param>
        /// <returns>non-null string</returns>
        #endregion
        static string GetPassword(int userId)
        {
            Contract.Requires(userId >= 0, "UserId must be");
            Contract.Ensures(Contract.Result<string>() != null);

            if (userId == 0)
            {
                // Made some code to log behavior

                // User doesn't exist
                return null;
            }
            else if (userId > 0)
            {
                return "Password";
            }

            return null;
        }
    }
}

Open in new window

Thanks.
0
Comment
Question by:zhshqzyc
1 Comment
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36543330
The Code Contracts library is a research project at Microsoft and is not provided with the framework.

You will get information about the library as well as downloan links at http://research.microsoft.com/en-us/projects/contracts/,
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now