forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryExtensions.cs
More file actions
44 lines (40 loc) · 1.69 KB
/
Copy pathDictionaryExtensions.cs
File metadata and controls
44 lines (40 loc) · 1.69 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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;
namespace Microsoft.EntityFrameworkCore.Internal
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
[DebuggerStepThrough]
internal static class DictionaryExtensions
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static TValue GetOrAddNew<TKey, TValue>(
[NotNull] this IDictionary<TKey, TValue> source,
[NotNull] TKey key)
where TValue : new()
{
if (!source.TryGetValue(key, out var value))
{
value = new TValue();
source.Add(key, value);
}
return value;
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static TValue Find<TKey, TValue>(
[NotNull] this IDictionary<TKey, TValue> source,
[NotNull] TKey key)
=> !source.TryGetValue(key, out var value) ? default : value;
}
}