Solved

System.Diagnostics.Contracts

Posted on 2011-09-15
1
303 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
[X]
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
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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