11
11
[ CLSCompliant ( false ) ]
12
12
public class ActionSelectionResult
13
13
{
14
- readonly HashSet < ActionDescriptor > candidateActions = new HashSet < ActionDescriptor > ( ) ;
15
- readonly HashSet < ActionDescriptor > matchingActions = new HashSet < ActionDescriptor > ( ) ;
14
+ HashSet < ActionDescriptor > ? candidateActions ;
15
+ HashSet < ActionDescriptor > ? matchingActions ;
16
16
17
17
/// <summary>
18
18
/// Gets the best action descriptor match.
@@ -21,21 +21,21 @@ public class ActionSelectionResult
21
21
/// <remarks>This property returns the first occurrence of a single match in the earliest iteration. If
22
22
/// no matches exist in any iteration or multiple matches exist, this property returns <c>null</c>.</remarks>
23
23
[ CLSCompliant ( false ) ]
24
- public ActionDescriptor ? BestMatch => MatchingActions . FirstOrDefault ( ) ;
24
+ public ActionDescriptor ? BestMatch => matchingActions ? . FirstOrDefault ( ) ;
25
25
26
26
/// <summary>
27
27
/// Gets a read-only collection of candidate actions.
28
28
/// </summary>
29
29
/// <value>A <see cref="IReadOnlyCollection{T}">read-only collection</see> of candidate <see cref="ActionDescriptor">actions</see>.</value>
30
30
[ CLSCompliant ( false ) ]
31
- public IReadOnlyCollection < ActionDescriptor > CandidateActions => candidateActions ;
31
+ public IReadOnlyCollection < ActionDescriptor > CandidateActions => candidateActions ??= new ( ) ;
32
32
33
33
/// <summary>
34
34
/// Gets a read-only collection of matching actions.
35
35
/// </summary>
36
36
/// <value>A <see cref="IReadOnlyCollection{T}">read-only collection</see> of <see cref="ActionDescriptor">matching actions</see>.</value>
37
37
[ CLSCompliant ( false ) ]
38
- public IReadOnlyCollection < ActionDescriptor > MatchingActions => matchingActions ;
38
+ public IReadOnlyCollection < ActionDescriptor > MatchingActions => matchingActions ??= new ( ) ;
39
39
40
40
/// <summary>
41
41
/// Adds the specified candidate actions to the selection result.
@@ -44,7 +44,7 @@ public class ActionSelectionResult
44
44
/// to add to the selection result.</param>
45
45
[ CLSCompliant ( false ) ]
46
46
public void AddCandidates ( IEnumerable < ActionDescriptor > actions ) =>
47
- candidateActions . AddRange ( actions ?? throw new ArgumentNullException ( nameof ( actions ) ) ) ;
47
+ ( candidateActions ??= new ( ) ) . AddRange ( actions ?? throw new ArgumentNullException ( nameof ( actions ) ) ) ;
48
48
49
49
/// <summary>
50
50
/// Adds the specified matching actions to the selection result.
@@ -53,6 +53,16 @@ public void AddCandidates( IEnumerable<ActionDescriptor> actions ) =>
53
53
/// to add to the selection result.</param>
54
54
[ CLSCompliant ( false ) ]
55
55
public void AddMatches ( IEnumerable < ActionDescriptor > matches ) =>
56
- matchingActions . AddRange ( matches ?? throw new ArgumentNullException ( nameof ( matches ) ) ) ;
56
+ ( matchingActions ??= new ( ) ) . AddRange ( matches ?? throw new ArgumentNullException ( nameof ( matches ) ) ) ;
57
+
58
+ /// <summary>
59
+ /// Clears the selection result.
60
+ /// </summary>
61
+ /// <remarks>The selection result should only ever be cleared if the routing middleware will be re-executed.</remarks>
62
+ public void Clear ( )
63
+ {
64
+ candidateActions ? . Clear ( ) ;
65
+ matchingActions ? . Clear ( ) ;
66
+ }
57
67
}
58
68
}
0 commit comments