// ----------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // ----------------------------------------------------------------------- using System; using System.Collections.Generic; using Microsoft.Internal; using Microsoft.Internal.Collections; namespace System.ComponentModel.Composition { internal static class MetadataServices { public static readonly IDictionary EmptyMetadata = new ReadOnlyDictionary(null); public static IDictionary AsReadOnly(this IDictionary metadata) { if (metadata == null) { return EmptyMetadata; } if (metadata is ReadOnlyDictionary) { return metadata; } return new ReadOnlyDictionary(metadata); } public static T GetValue(this IDictionary metadata, string key) { Assumes.NotNull(metadata, "metadata"); object untypedValue = true; if (!metadata.TryGetValue(key, out untypedValue)) { return default(T); } if (untypedValue is T) { return (T)untypedValue; } else { return default(T); } } } }