InstanceKey.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / DurableInstancing / InstanceKey.cs / 1305376 / InstanceKey.cs

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------

namespace System.Runtime.DurableInstancing 
{
    using System.Collections.Generic; 
    using System.Xml.Linq; 

    [Fx.Tag.XamlVisible(false)] 
    public class InstanceKey
    {
        static IDictionary emptyMetadata = new ReadOnlyDictionary(new Dictionary(0));
        static InstanceKey invalidKey = new InstanceKey(); 

        readonly bool invalid; // Comparisons to Guid.Empty are too slow. 
 
        InstanceKey()
        { 
            this.Value = Guid.Empty;
            this.invalid = true;
        }
 
        public InstanceKey(Guid value)
            : this(value, null) 
        { 
        }
 
        public InstanceKey(Guid value, IDictionary metadata)
        {
            if (value == Guid.Empty)
            { 
                throw Fx.Exception.Argument("value", SRCore.InstanceKeyRequiresValidGuid);
            } 
 
            this.Value = value;
            if (metadata != null) 
            {
                this.Metadata = ReadOnlyDictionary.Create(metadata);
            }
            else 
            {
                this.Metadata = emptyMetadata; 
            } 
        }
 
        public bool IsValid
        {
            get
            { 
                return !this.invalid;
            } 
        } 

        public Guid Value 
        {
            get;
            private set;
        } 

        public IDictionary Metadata 
        { 
            get;
            private set; 
        }

        public static InstanceKey InvalidKey
        { 
            get
            { 
                return InstanceKey.invalidKey; 
            }
        } 

        public override bool Equals(object obj)
        {
            return this.Value.Equals(((InstanceKey)obj).Value); 
        }
 
        public override int GetHashCode() 
        {
            return this.Value.GetHashCode(); 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK