-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAnnotationProperties.cs
73 lines (60 loc) · 2.01 KB
/
AnnotationProperties.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
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.
namespace Actions.Core;
/// <summary>
/// Inspired by <a href="https://github.com/actions/toolkit/blob/main/packages/core/src/core.ts#L40"></a>
/// </summary>
public readonly record struct AnnotationProperties
{
/// <summary>
/// A title for the annotation.
/// </summary>
public string? Title { get; init; }
/// <summary>
/// The path of the file for which the annotation should be created.
/// </summary>
public string? File { get; init; }
/// <summary>
/// The start line of the annotation.
/// </summary>
public int? StartLine { get; init; }
/// <summary>
/// The end line of the annotation.
/// </summary>
public int? EndLine { get; init; }
/// <summary>
/// The start column of the annotation.
/// </summary>
public int? StartColumn { get; init; }
/// <summary>
/// The end column of the annotation.
/// </summary>
public int? EndColumn { get; init; }
private bool IsEmpty => Equals(default);
/// <summary>
/// Converts the current annotations instance into a readonly dictionary.
/// </summary>
public IReadOnlyDictionary<string, string> ToCommandProperties()
{
if (IsEmpty)
{
return new Dictionary<string, string>();
}
var properties = new Dictionary<string, string>();
TryAddProperty(properties, "title", Title);
TryAddProperty(properties, "file", File);
TryAddProperty(properties, "line", StartLine);
TryAddProperty(properties, "endLine", EndLine);
TryAddProperty(properties, "col", StartColumn);
TryAddProperty(properties, "endColumn", EndColumn);
return properties;
static void TryAddProperty(
in IDictionary<string, string> properties, string key, object? value)
{
if (value is not null)
{
properties[key] = value.ToString()!;
}
}
}
}