HybridObjectCache.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Serialization / System / Runtime / Serialization / HybridObjectCache.cs / 1305376 / HybridObjectCache.cs

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

namespace System.Runtime.Serialization 
{
    using System; 
    using System.Xml; 
    using System.Collections.Generic;
 
    internal class HybridObjectCache
    {
        Dictionary objectDictionary;
        Dictionary referencedObjectDictionary; 

        internal HybridObjectCache() 
        { 
        }
 
        internal void Add(string id, object obj)
        {
            if (objectDictionary == null)
                objectDictionary = new Dictionary(); 

            object existingObject; 
            if (objectDictionary.TryGetValue(id, out existingObject)) 
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.MultipleIdDefinition, id)));
            objectDictionary.Add(id, obj); 
        }

        internal void Remove(string id)
        { 
            if (objectDictionary != null)
                objectDictionary.Remove(id); 
        } 

        internal object GetObject(string id) 
        {
            if (referencedObjectDictionary == null)
            {
                referencedObjectDictionary = new Dictionary(); 
                referencedObjectDictionary.Add(id, null);
            } 
            else if (!referencedObjectDictionary.ContainsKey(id)) 
            {
                referencedObjectDictionary.Add(id, null); 
            }

            if (objectDictionary != null)
            { 
                object obj;
                objectDictionary.TryGetValue(id, out obj); 
                return obj; 
            }
 
            return null;
        }

        internal bool IsObjectReferenced(string id) 
        {
            if (referencedObjectDictionary != null) 
            { 
                return referencedObjectDictionary.ContainsKey(id);
            } 
            return false;
        }

    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.Runtime.Serialization 
{
    using System; 
    using System.Xml; 
    using System.Collections.Generic;
 
    internal class HybridObjectCache
    {
        Dictionary objectDictionary;
        Dictionary referencedObjectDictionary; 

        internal HybridObjectCache() 
        { 
        }
 
        internal void Add(string id, object obj)
        {
            if (objectDictionary == null)
                objectDictionary = new Dictionary(); 

            object existingObject; 
            if (objectDictionary.TryGetValue(id, out existingObject)) 
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.MultipleIdDefinition, id)));
            objectDictionary.Add(id, obj); 
        }

        internal void Remove(string id)
        { 
            if (objectDictionary != null)
                objectDictionary.Remove(id); 
        } 

        internal object GetObject(string id) 
        {
            if (referencedObjectDictionary == null)
            {
                referencedObjectDictionary = new Dictionary(); 
                referencedObjectDictionary.Add(id, null);
            } 
            else if (!referencedObjectDictionary.ContainsKey(id)) 
            {
                referencedObjectDictionary.Add(id, null); 
            }

            if (objectDictionary != null)
            { 
                object obj;
                objectDictionary.TryGetValue(id, out obj); 
                return obj; 
            }
 
            return null;
        }

        internal bool IsObjectReferenced(string id) 
        {
            if (referencedObjectDictionary != null) 
            { 
                return referencedObjectDictionary.ContainsKey(id);
            } 
            return false;
        }

    } 
}

// 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