forked from dotnet/msbuild
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProjectCacheItem.cs
70 lines (55 loc) · 1.97 KB
/
ProjectCacheItem.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Shared;
namespace Microsoft.Build.Experimental.ProjectCache
{
internal class ProjectCacheItem : IEquatable<ProjectCacheItem>
{
private readonly IReadOnlyCollection<KeyValuePair<string, string>> _pluginSettingsSorted;
public ProjectCacheItem(string pluginPath, IReadOnlyDictionary<string, string> pluginSettings)
{
PluginPath = pluginPath;
PluginSettings = pluginSettings;
// Sort by key to avoid doing it during hashcode computation.
_pluginSettingsSorted = pluginSettings.OrderBy(_ => _.Key).ToArray();
}
public string PluginPath { get; }
public IReadOnlyDictionary<string, string> PluginSettings { get; }
public bool Equals(ProjectCacheItem other)
{
if (ReferenceEquals(this, other))
{
return true;
}
return PluginPath == other.PluginPath &&
CollectionHelpers.DictionaryEquals(PluginSettings, other.PluginSettings);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((ProjectCacheItem) obj);
}
public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(PluginPath);
foreach (var pluginSetting in _pluginSettingsSorted)
{
hashCode.Add(pluginSetting.Key);
hashCode.Add(pluginSetting.Value);
}
return hashCode.ToHashCode();
}
}
}