-
Notifications
You must be signed in to change notification settings - Fork 1k
/
ManifestVersionUpdate.cs
87 lines (77 loc) · 3.93 KB
/
ManifestVersionUpdate.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
public class ManifestVersionUpdate : IEquatable<ManifestVersionUpdate>, IComparable<ManifestVersionUpdate>
{
public ManifestVersionUpdate(ManifestId manifestId, ManifestVersion? existingVersion, string? existingFeatureBand, ManifestVersion? newVersion, string? newFeatureBand)
{
ManifestId = manifestId;
ExistingVersion = existingVersion;
ExistingFeatureBand = existingFeatureBand;
NewVersion = newVersion;
NewFeatureBand = newFeatureBand;
}
public ManifestId ManifestId { get; }
public ManifestVersion? ExistingVersion { get; }
public string? ExistingFeatureBand { get; }
public ManifestVersion? NewVersion { get; }
public string? NewFeatureBand { get; }
// Returns an object representing an undo of this manifest update
public ManifestVersionUpdate Reverse()
{
return new ManifestVersionUpdate(ManifestId, NewVersion, NewFeatureBand, ExistingVersion, ExistingFeatureBand);
}
public int CompareTo(ManifestVersionUpdate? other)
{
if (other == null) return 1;
int ret = ManifestId.CompareTo(other.ManifestId);
if (ret != 0) return ret;
if (ExistingVersion == null && other.ExistingVersion != null) return -1;
if (ExistingVersion != null && other.ExistingVersion == null) return 1;
if (ExistingVersion != null)
{
ret = ExistingVersion.CompareTo(other.ExistingVersion);
if (ret != 0) return ret;
}
ret = string.Compare(ExistingFeatureBand, other.ExistingFeatureBand, StringComparison.Ordinal);
if (ret != 0) return ret;
if (NewVersion == null && other.NewVersion != null) return -1;
if (NewVersion != null && other.NewVersion == null) return 1;
if (NewVersion != null)
{
ret = NewVersion.CompareTo(other.NewVersion);
if (ret != 0) return ret;
}
ret = string.Compare(NewFeatureBand, other.NewFeatureBand, StringComparison.Ordinal);
return ret;
}
public bool Equals(ManifestVersionUpdate? other)
{
if (other == null) return false;
return EqualityComparer<ManifestId>.Default.Equals(ManifestId, other.ManifestId) &&
EqualityComparer<ManifestVersion?>.Default.Equals(ExistingVersion, other.ExistingVersion) &&
string.Equals(ExistingFeatureBand, other.ExistingFeatureBand, StringComparison.Ordinal) &&
EqualityComparer<ManifestVersion?>.Default.Equals(NewVersion, other.NewVersion) &&
string.Equals(NewFeatureBand, other.NewFeatureBand, StringComparison.Ordinal);
}
public override bool Equals(object? obj)
{
return obj is ManifestVersionUpdate id && Equals(id);
}
public override int GetHashCode()
{
#if NETCOREAPP3_1_OR_GREATER
return HashCode.Combine(ManifestId, ExistingVersion, ExistingFeatureBand, NewVersion, NewFeatureBand);
#else
int hashCode = 1601069575;
hashCode = hashCode * -1521134295 + ManifestId.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<ManifestVersion?>.Default.GetHashCode(ExistingVersion);
hashCode = hashCode * -1521134295 + EqualityComparer<string?>.Default.GetHashCode(ExistingFeatureBand);
hashCode = hashCode * -1521134295 + EqualityComparer<ManifestVersion?>.Default.GetHashCode(NewVersion);
hashCode = hashCode * -1521134295 + EqualityComparer<string?>.Default.GetHashCode(NewFeatureBand);
return hashCode;
#endif
}
}
}