Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

70 lines
2.1 KiB
C#

//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Runtime.Serialization
{
using System;
using System.Xml;
using System.Collections.Generic;
internal class HybridObjectCache
{
Dictionary<string, object> objectDictionary;
Dictionary<string, object> referencedObjectDictionary;
internal HybridObjectCache()
{
}
internal void Add(string id, object obj)
{
if (objectDictionary == null)
objectDictionary = new Dictionary<string, object>();
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<string, object>();
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;
}
}
}