Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

System.Diagnostics.Contracts

Posted on 2011-09-15
1
299 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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