3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // <OWNER>Microsoft</OWNER>
8 // <OWNER>Microsoft</OWNER>
11 using System.Collections.Generic;
12 using System.Diagnostics.Contracts;
14 namespace System.Runtime.InteropServices.WindowsRuntime
16 // Provides access to a System.Collections.Generic.KeyValuePair<K, V> via the IKeyValuePair<K, V> WinRT interface.
17 internal sealed class CLRIKeyValuePairImpl<K, V> : IKeyValuePair<K, V>
19 private readonly KeyValuePair<K, V> _pair;
21 public CLRIKeyValuePairImpl([In] ref KeyValuePair<K, V> pair)
26 // IKeyValuePair<K, V> implementation
30 get { return _pair.Key; }
36 get { return _pair.Value; }
39 // Called from the VM to wrap a boxed KeyValuePair with a CLRIKeyValuePairImpl.
40 internal static object BoxHelper(object pair)
42 Contract.Requires(pair != null);
44 KeyValuePair<K, V> unboxedPair = (KeyValuePair<K, V>)pair;
45 return new CLRIKeyValuePairImpl<K, V>(ref unboxedPair);
48 // Called from the VM to get a boxed KeyValuePair out of a CLRIKeyValuePairImpl.
49 internal static object UnboxHelper(object wrapper)
51 Contract.Requires(wrapper != null);
53 CLRIKeyValuePairImpl<K, V> reference = (CLRIKeyValuePairImpl<K, V>)wrapper;
54 return reference._pair;
57 public override string ToString()
59 return _pair.ToString();