Nullable: System.Runtime.InteropServices.CustomMarshalers/WindowsRuntime (#23930)
[platform/upstream/coreclr.git] / src / System.Private.CoreLib / src / System / Runtime / InteropServices / WindowsRuntime / CLRIKeyValuePairImpl.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 #nullable enable
6 using System.Collections.Generic;
7 using System.Diagnostics;
8
9 namespace System.Runtime.InteropServices.WindowsRuntime
10 {
11     // Provides access to a System.Collections.Generic.KeyValuePair<K, V> via the IKeyValuePair<K, V> WinRT interface.
12     internal sealed class CLRIKeyValuePairImpl<K, V> : IKeyValuePair<K, V>,
13                                                        IGetProxyTarget
14     {
15         private readonly KeyValuePair<K, V> _pair;
16
17         public CLRIKeyValuePairImpl([In] ref KeyValuePair<K, V> pair)
18         {
19             _pair = pair;
20         }
21
22         // IKeyValuePair<K, V> implementation
23         public K Key
24         {
25             get { return _pair.Key; }
26         }
27
28         public V Value
29         {
30             get { return _pair.Value; }
31         }
32
33         // Called from the VM to wrap a boxed KeyValuePair with a CLRIKeyValuePairImpl.
34         internal static object BoxHelper(object pair)
35         {
36             Debug.Assert(pair != null);
37
38             KeyValuePair<K, V> unboxedPair = (KeyValuePair<K, V>)pair;
39             return new CLRIKeyValuePairImpl<K, V>(ref unboxedPair);
40         }
41
42         // Called from the VM to get a boxed KeyValuePair out of a CLRIKeyValuePairImpl.
43         internal static object UnboxHelper(object wrapper)
44         {
45             Debug.Assert(wrapper != null);
46
47             CLRIKeyValuePairImpl<K, V> reference = (CLRIKeyValuePairImpl<K, V>)wrapper;
48             return reference._pair;
49         }
50
51         public override string ToString()
52         {
53             return _pair.ToString();
54         }
55
56         object IGetProxyTarget.GetTarget()
57         {
58             return _pair;
59         }
60     }
61 }