1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using System.Collections.Generic;
\r
6 using Microsoft.Internal;
\r
7 using Microsoft.Internal.Collections;
\r
9 namespace System.ComponentModel.Composition
\r
11 internal static class MetadataServices
\r
13 public static readonly IDictionary<string, object> EmptyMetadata = new ReadOnlyDictionary<string, object>(null);
\r
15 public static IDictionary<string, object> AsReadOnly(this IDictionary<string, object> metadata)
\r
17 if (metadata == null)
\r
19 return EmptyMetadata;
\r
22 if (metadata is ReadOnlyDictionary<string, object>)
\r
27 return new ReadOnlyDictionary<string, object>(metadata);
\r
30 public static T GetValue<T>(this IDictionary<string, object> metadata, string key)
\r
32 Assumes.NotNull(metadata, "metadata");
\r
34 object untypedValue = true;
\r
35 if (!metadata.TryGetValue(key, out untypedValue))
\r
40 if (untypedValue is T)
\r
42 return (T)untypedValue;
\r