summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs')
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
new file mode 100644
index 0000000000..683a7f3327
--- /dev/null
+++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
@@ -0,0 +1,58 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+//
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Contracts;
+
+namespace System.Runtime.InteropServices.WindowsRuntime
+{
+ // Provides access to a System.Collections.Generic.KeyValuePair<K, V> via the IKeyValuePair<K, V> WinRT interface.
+ internal sealed class CLRIKeyValuePairImpl<K, V> : IKeyValuePair<K, V>
+ {
+ private readonly KeyValuePair<K, V> _pair;
+
+ public CLRIKeyValuePairImpl([In] ref KeyValuePair<K, V> pair)
+ {
+ _pair = pair;
+ }
+
+ // IKeyValuePair<K, V> implementation
+ [Pure]
+ public K Key
+ {
+ get { return _pair.Key; }
+ }
+
+ [Pure]
+ public V Value
+ {
+ get { return _pair.Value; }
+ }
+
+ // Called from the VM to wrap a boxed KeyValuePair with a CLRIKeyValuePairImpl.
+ internal static object BoxHelper(object pair)
+ {
+ Contract.Requires(pair != null);
+
+ KeyValuePair<K, V> unboxedPair = (KeyValuePair<K, V>)pair;
+ return new CLRIKeyValuePairImpl<K, V>(ref unboxedPair);
+ }
+
+ // Called from the VM to get a boxed KeyValuePair out of a CLRIKeyValuePairImpl.
+ internal static object UnboxHelper(object wrapper)
+ {
+ Contract.Requires(wrapper != null);
+
+ CLRIKeyValuePairImpl<K, V> reference = (CLRIKeyValuePairImpl<K, V>)wrapper;
+ return reference._pair;
+ }
+
+ public override string ToString()
+ {
+ return _pair.ToString();
+ }
+ }
+}