-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathPipComponent.cs
More file actions
47 lines (37 loc) · 1.58 KB
/
Copy pathPipComponent.cs
File metadata and controls
47 lines (37 loc) · 1.58 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
#nullable disable
namespace Microsoft.ComponentDetection.Contracts.TypedComponent;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using PackageUrl;
public class PipComponent : TypedComponent
{
public PipComponent()
{
/* Reserved for deserialization */
}
public PipComponent(string name, string version, string author = null, string license = null)
{
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Pip));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Pip));
this.Author = author;
this.License = license;
}
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
#nullable enable
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("author")]
public string? Author { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("license")]
public string? License { get; set; }
#nullable disable
[JsonIgnore]
public override ComponentType Type => ComponentType.Pip;
[JsonPropertyName("packageUrl")]
public override PackageURL PackageUrl => new PackageURL("pypi", null, this.Name, this.Version, null, null);
[SuppressMessage("Usage", "CA1308:Normalize String to Uppercase", Justification = "Casing cannot be overwritten.")]
protected override string ComputeBaseId() => $"{this.Name} {this.Version} - {this.Type}".ToLowerInvariant();
}