-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathSdkResult.cs
More file actions
192 lines (166 loc) · 7.35 KB
/
SdkResult.cs
File metadata and controls
192 lines (166 loc) · 7.35 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Framework;
using SdkReference = Microsoft.Build.Framework.SdkReference;
using SdkResultBase = Microsoft.Build.Framework.SdkResult;
#nullable disable
namespace Microsoft.Build.BackEnd.SdkResolution
{
/// <summary>
/// An internal implementation of <see cref="Framework.SdkResult"/>.
/// </summary>
internal sealed class SdkResult : SdkResultBase, INodePacket
{
public SdkResult(ITranslator translator)
{
Translate(translator);
}
public SdkResult(SdkReference sdkReference, IEnumerable<string> errors, IEnumerable<string> warnings)
{
Success = false;
SdkReference = sdkReference;
Errors = errors;
Warnings = warnings;
}
public SdkResult(SdkReference sdkReference, string path, string version, IEnumerable<string> warnings,
IDictionary<string, string> propertiesToAdd = null, IDictionary<string, SdkResultItem> itemsToAdd = null, IDictionary<string, string> environmentVariablesToAdd = null)
{
Success = true;
SdkReference = sdkReference;
Path = path;
Version = version;
Warnings = warnings;
PropertiesToAdd = propertiesToAdd;
ItemsToAdd = itemsToAdd;
EnvironmentVariablesToAdd = environmentVariablesToAdd;
}
public SdkResult()
{
}
public SdkResult(SdkReference sdkReference, IEnumerable<string> paths, string version, IDictionary<string, string> propertiesToAdd,
IDictionary<string, SdkResultItem> itemsToAdd, IEnumerable<string> warnings, IDictionary<string, string> environmentVariablesToAdd = null)
{
Success = true;
SdkReference = sdkReference;
if (paths != null)
{
var firstPath = paths.FirstOrDefault();
if (firstPath != null)
{
Path = firstPath;
}
if (paths.Count() > 1)
{
AdditionalPaths = paths.Skip(1).ToList();
}
}
Version = version;
// Note: these dictionaries should use StringComparison.OrdinalIgnoreCase
PropertiesToAdd = propertiesToAdd;
ItemsToAdd = itemsToAdd;
EnvironmentVariablesToAdd = environmentVariablesToAdd;
Warnings = warnings;
}
public Construction.ElementLocation ElementLocation { get; set; }
public IEnumerable<string> Errors { get; }
public IEnumerable<string> Warnings { get; }
public void Translate(ITranslator translator)
{
translator.Translate(ref _success);
translator.Translate(ref _path);
translator.Translate(ref _version);
translator.Translate(ref _additionalPaths, (ITranslator t, ref string s) => t.Translate(ref s), count => new List<string>(count));
translator.TranslateDictionary(ref _propertiesToAdd, count => new Dictionary<string, string>(count, StringComparer.OrdinalIgnoreCase));
translator.TranslateDictionary(ref _itemsToAdd,
keyTranslator: (ITranslator t, ref string s) => t.Translate(ref s),
valueTranslator: SdkResultTranslationHelpers.Translate,
dictionaryCreator: count => new Dictionary<string, SdkResultItem>(count, StringComparer.OrdinalIgnoreCase));
translator.Translate(ref _sdkReference);
}
public NodePacketType Type => NodePacketType.ResolveSdkResponse;
public static INodePacket FactoryForDeserialization(ITranslator translator)
{
return new SdkResult(translator);
}
public override bool Equals(object obj)
{
if (obj is SdkResult result &&
_success == result._success &&
StringComparer.OrdinalIgnoreCase.Equals(_path, result._path) &&
StringComparer.OrdinalIgnoreCase.Equals(_version, result._version) &&
_additionalPaths?.Count == result._additionalPaths?.Count &&
_propertiesToAdd?.Count == result._propertiesToAdd?.Count &&
_itemsToAdd?.Count == result._itemsToAdd?.Count &&
EqualityComparer<SdkReference>.Default.Equals(_sdkReference, result._sdkReference))
{
if (_additionalPaths != null)
{
for (int i = 0; i < _additionalPaths.Count; i++)
{
if (!_additionalPaths[i].Equals(result._additionalPaths[i], StringComparison.OrdinalIgnoreCase))
{
return false;
}
}
}
if (_propertiesToAdd != null)
{
foreach (var propertyToAdd in _propertiesToAdd)
{
if (result._propertiesToAdd[propertyToAdd.Key] != propertyToAdd.Value)
{
return false;
}
}
}
if (_itemsToAdd != null)
{
foreach (var itemToAdd in _itemsToAdd)
{
if (!result._itemsToAdd[itemToAdd.Key].Equals(itemToAdd.Value))
{
return false;
}
}
}
return true;
}
return false;
}
public override int GetHashCode()
{
int hashCode = -1043047289;
hashCode = (hashCode * -1521134295) + _success.GetHashCode();
hashCode = (hashCode * -1521134295) + StringComparer.OrdinalIgnoreCase.GetHashCode(_path);
hashCode = (hashCode * -1521134295) + StringComparer.OrdinalIgnoreCase.GetHashCode(_version);
hashCode = (hashCode * -1521134295) + EqualityComparer<SdkReference>.Default.GetHashCode(_sdkReference);
if (_additionalPaths != null)
{
foreach (var additionalPath in _additionalPaths)
{
hashCode = (hashCode * -1521134295) + StringComparer.OrdinalIgnoreCase.GetHashCode(additionalPath);
}
}
if (_propertiesToAdd != null)
{
foreach (var propertyToAdd in _propertiesToAdd)
{
hashCode = (hashCode * -1521134295) + propertyToAdd.Key.GetHashCode();
hashCode = (hashCode * -1521134295) + propertyToAdd.Value.GetHashCode();
}
}
if (_itemsToAdd != null)
{
foreach (var itemToAdd in _itemsToAdd)
{
hashCode = (hashCode * -1521134295) + itemToAdd.Key.GetHashCode();
hashCode = (hashCode * -1521134295) + itemToAdd.Value.GetHashCode();
}
}
return hashCode;
}
}
}