5
5
6
6
namespace PSRule . Definitions ;
7
7
8
- internal sealed class ResultReason : IResultReasonV2
8
+ #nullable enable
9
+
10
+ /// <summary>
11
+ /// A reason for the rule result.
12
+ /// </summary>
13
+ internal sealed class ResultReason : IResultReason
9
14
{
10
- private string _Path ;
11
- private string _Formatted ;
12
- private string _Message ;
13
- private string _FullPath ;
14
15
private readonly string _ParentPath ;
15
16
16
- internal ResultReason ( string parentPath , IOperand operand , string text , object [ ] args )
17
+ private string ? _Path ;
18
+ private string ? _Formatted ;
19
+ private string ? _Message ;
20
+ private string ? _FullPath ;
21
+
22
+ internal ResultReason ( string ? parentPath , IOperand ? operand , string text , object [ ] ? args )
17
23
{
18
- _ParentPath = parentPath ;
24
+ _ParentPath = parentPath ?? string . Empty ;
19
25
Operand = operand ;
20
26
_Path = Operand ? . Path ;
21
27
Text = text ;
22
28
Args = args ;
23
29
}
24
30
25
- internal IOperand Operand { get ; }
31
+ internal IOperand ? Operand { get ; }
26
32
27
33
/// <summary>
28
34
/// The object path that failed.
@@ -31,15 +37,14 @@ public string Path
31
37
{
32
38
get
33
39
{
34
- _Path ??= GetPath ( ) ;
35
- return _Path ;
40
+ return _Path ??= GetPath ( ) ;
36
41
}
37
42
}
38
43
39
44
/// <summary>
40
45
/// A prefix to add to the object path that failed.
41
46
/// </summary>
42
- internal string Prefix
47
+ internal string ? Prefix
43
48
{
44
49
get { return Operand ? . Prefix ; }
45
50
set
@@ -59,21 +64,20 @@ public string FullPath
59
64
{
60
65
get
61
66
{
62
- _FullPath ??= GetFullPath ( ) ;
63
- return _FullPath ;
67
+ return _FullPath ??= GetFullPath ( ) ;
64
68
}
65
69
}
66
70
67
71
public string Text { get ; }
68
72
69
- public object [ ] Args { get ; }
73
+ public object [ ] ? Args { get ; }
70
74
75
+ /// <inheritdoc/>
71
76
public string Message
72
77
{
73
78
get
74
79
{
75
- _Message ??= Args == null || Args . Length == 0 ? Text : string . Format ( Thread . CurrentThread . CurrentCulture , Text , Args ) ;
76
- return _Message ;
80
+ return _Message ??= Args == null || Args . Length == 0 ? Text : string . Format ( Thread . CurrentThread . CurrentCulture , Text , Args ) ;
77
81
}
78
82
}
79
83
@@ -82,13 +86,23 @@ public override string ToString()
82
86
return Format ( ) ;
83
87
}
84
88
89
+ public override int GetHashCode ( )
90
+ {
91
+ return ToString ( ) . GetHashCode ( ) ;
92
+ }
93
+
94
+ public override bool Equals ( object obj )
95
+ {
96
+ return obj is IResultReason other && Equals ( other ) ;
97
+ }
98
+
99
+ /// <inheritdoc/>
85
100
public string Format ( )
86
101
{
87
- _Formatted ??= string . Concat (
102
+ return _Formatted ??= string . Concat (
88
103
Operand ? . ToString ( ) ,
89
104
Message
90
105
) ;
91
- return _Formatted ;
92
106
}
93
107
94
108
private string GetPath ( )
@@ -100,4 +114,17 @@ private string GetFullPath()
100
114
{
101
115
return Runtime . Operand . JoinPath ( _ParentPath , Path ) ;
102
116
}
117
+
118
+ #region IEquatable<IResultReason>
119
+
120
+ public bool Equals ( IResultReason ? other )
121
+ {
122
+ return other != null &&
123
+ string . Equals ( FullPath , other . FullPath , StringComparison . Ordinal ) &&
124
+ string . Equals ( Message , other . Message , StringComparison . Ordinal ) ;
125
+ }
126
+
127
+ #endregion IEquatable<IResultReason>
103
128
}
129
+
130
+ #nullable restore
0 commit comments