-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathKeyValuePair.cs
More file actions
56 lines (47 loc) · 2 KB
/
KeyValuePair.cs
File metadata and controls
56 lines (47 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
namespace System.Collections.Generic
{
// Provides the Create factory method for KeyValuePair<TKey, TValue>.
public static class KeyValuePair
{
// Creates a new KeyValuePair<TKey, TValue> from the given values.
public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(TKey key, TValue value) =>
new KeyValuePair<TKey, TValue>(key, value);
/// <summary>Used by KeyValuePair.ToString to reduce generic code</summary>
internal static string PairToString(object? key, object? value) =>
string.Create(null, stackalloc char[256], $"[{key}, {value}]");
}
// A KeyValuePair holds a key and a value from a dictionary.
// It is used by the IEnumerable<T> implementation for both IDictionary<TKey, TValue>
// and IReadOnlyDictionary<TKey, TValue>.
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct KeyValuePair<TKey, TValue>
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly TKey key; // Do not rename (binary serialization)
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly TValue value; // Do not rename (binary serialization)
public KeyValuePair(TKey key, TValue value)
{
this.key = key;
this.value = value;
}
public TKey Key => key;
public TValue Value => value;
public override string ToString()
{
return KeyValuePair.PairToString(Key, Value);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void Deconstruct(out TKey key, out TValue value)
{
key = Key;
value = Value;
}
}
}