Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / mscorlib / system / runtime / interopservices / windowsruntime / clrikeyvaluepairimpl.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 //
7 // <OWNER>Microsoft</OWNER>
8 // <OWNER>Microsoft</OWNER>
9
10 using System;
11 using System.Collections.Generic;
12 using System.Diagnostics.Contracts;
13
14 namespace System.Runtime.InteropServices.WindowsRuntime
15 {
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>
18     {
19         private readonly KeyValuePair<K, V> _pair;
20
21         public CLRIKeyValuePairImpl([In] ref KeyValuePair<K, V> pair)
22         {
23             _pair = pair;
24         }
25
26         // IKeyValuePair<K, V> implementation
27         [Pure]
28         public K Key
29         {
30             get { return _pair.Key; }
31         }
32
33         [Pure]
34         public V Value
35         {
36             get { return _pair.Value; }
37         }
38
39         // Called from the VM to wrap a boxed KeyValuePair with a CLRIKeyValuePairImpl.
40         internal static object BoxHelper(object pair)
41         {
42             Contract.Requires(pair != null);
43
44             KeyValuePair<K, V> unboxedPair = (KeyValuePair<K, V>)pair;
45             return new CLRIKeyValuePairImpl<K, V>(ref unboxedPair);
46         }
47
48         // Called from the VM to get a boxed KeyValuePair out of a CLRIKeyValuePairImpl.
49         internal static object UnboxHelper(object wrapper)
50         {
51             Contract.Requires(wrapper != null);
52             
53             CLRIKeyValuePairImpl<K, V> reference = (CLRIKeyValuePairImpl<K, V>)wrapper;
54             return reference._pair;
55         }
56
57         public override string ToString()
58         {
59             return _pair.ToString();
60         }
61     }
62 }