diff options
Diffstat (limited to 'src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs')
-rw-r--r-- | src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs | 66 |
1 files changed, 66 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..3a52d12234 --- /dev/null +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more 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>, + IGetProxyTarget + { + 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(); + } + + object IGetProxyTarget.GetTarget() + { + return _pair; + } + + } +} |