-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathGoComponent.cs
More file actions
67 lines (53 loc) · 2.22 KB
/
Copy pathGoComponent.cs
File metadata and controls
67 lines (53 loc) · 2.22 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
#nullable disable
namespace Microsoft.ComponentDetection.Contracts.TypedComponent;
using System;
using System.Text.Json.Serialization;
using PackageUrl;
public class GoComponent : TypedComponent, IEquatable<GoComponent>
{
public GoComponent(string name, string version)
{
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Go));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Go));
this.Hash = string.Empty;
}
public GoComponent(string name, string version, string hash)
{
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Go));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Go));
this.Hash = this.ValidateRequiredInput(hash, nameof(this.Hash), nameof(ComponentType.Go));
}
public GoComponent()
{
/* Reserved for deserialization */
}
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("hash")]
public string Hash { get; set; }
// Commit should be used in place of version when available
// https://github.com/package-url/purl-spec/blame/180c46d266c45aa2bd81a2038af3f78e87bb4a25/README.rst#L610
[JsonPropertyName("packageUrl")]
public override PackageURL PackageUrl => new PackageURL("golang", null, this.Name, string.IsNullOrWhiteSpace(this.Hash) ? this.Version : this.Hash, null, null);
[JsonIgnore]
public override ComponentType Type => ComponentType.Go;
protected override string ComputeBaseId() => $"{this.Name} {this.Version} - {this.Type}";
public override bool Equals(object obj)
{
return obj is GoComponent otherComponent && this.Equals(otherComponent);
}
public bool Equals(GoComponent other)
{
if (other == null)
{
return false;
}
return this.Name == other.Name && this.Version == other.Version && this.Hash == other.Hash;
}
public override int GetHashCode()
{
return this.Name.GetHashCode() ^ this.Version.GetHashCode() ^ this.Hash.GetHashCode();
}
}