//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------- namespace System.Runtime.DurableInstancing { using System.Collections.Generic; using System.Collections.ObjectModel; using System.Xml.Linq; [Fx.Tag.XamlVisible(false)] public sealed class InstanceOwnerQueryResult : InstanceStoreQueryResult { static readonly ReadOnlyDictionaryInternal> EmptyQueryResult = new ReadOnlyDictionaryInternal>(new Dictionary>(0)); static readonly ReadOnlyDictionaryInternal EmptyMetadata = new ReadOnlyDictionaryInternal(new Dictionary(0)); // Zero public InstanceOwnerQueryResult() { InstanceOwners = EmptyQueryResult; } // One public InstanceOwnerQueryResult(Guid instanceOwnerId, IDictionary metadata) { Dictionary> owners = new Dictionary>(1); IDictionary safeMetadata; // if metadata is not readonly, copy it. if (metadata == null || metadata.IsReadOnly) safeMetadata = metadata; else { // Copy dictionary & make a readonly wrapper. IDictionary copy = new Dictionary(metadata); safeMetadata = new ReadOnlyDictionaryInternal(copy); } owners.Add(instanceOwnerId, metadata == null ? EmptyMetadata : safeMetadata); InstanceOwners = new ReadOnlyDictionaryInternal>(owners); } // N public InstanceOwnerQueryResult(IDictionary> instanceOwners) { Dictionary> owners = new Dictionary>(instanceOwners.Count); foreach (KeyValuePair> metadata in instanceOwners) { IDictionary safeMetadata; // if metadata is not readonly, copy it. if (metadata.Value == null || metadata.Value.IsReadOnly) safeMetadata = metadata.Value; else { // Copy dictionary & make a readonly wrapper. IDictionary copy = new Dictionary(metadata.Value); safeMetadata = new ReadOnlyDictionaryInternal(copy); } owners.Add(metadata.Key, metadata.Value == null ? EmptyMetadata : safeMetadata); } InstanceOwners = new ReadOnlyDictionaryInternal>(owners); } public IDictionary> InstanceOwners { get; private set; } } }