Make collections in activity descriptor read-only

This commit is contained in:
Sipke Schoorstra 2023-06-28 18:07:16 +02:00
parent 90d1905e46
commit e0dd53b1ad
2 changed files with 5 additions and 13 deletions

View file

@ -43,12 +43,12 @@ public record ActivityDescriptor
/// <summary>
/// The input properties of the activity type.
/// </summary>
public ICollection<InputDescriptor> Inputs { get; init; } = new List<InputDescriptor>();
public IReadOnlyCollection<InputDescriptor> Inputs { get; init; } = new List<InputDescriptor>();
/// <summary>
/// The output properties of the activity type.
/// </summary>
public ICollection<OutputDescriptor> Outputs { get; init; } = new List<OutputDescriptor>();
public IReadOnlyCollection<OutputDescriptor> Outputs { get; init; } = new List<OutputDescriptor>();
/// <summary>
/// The kind of activity.
@ -58,12 +58,12 @@ public record ActivityDescriptor
/// <summary>
/// The ports of the activity type.
/// </summary>
public ICollection<Port> Ports { get; init; } = new List<Port>();
public IReadOnlyCollection<Port> Ports { get; init; } = new List<Port>();
/// <summary>
/// The custom properties of the activity type.
/// </summary>
public IDictionary<string, object> CustomProperties { get; set; } = new Dictionary<string, object>();
public IReadOnlyDictionary<string, object> CustomProperties { get; set; } = new Dictionary<string, object>();
/// <summary>
/// A value indicating whether this activity is a container of child activities.

View file

@ -30,12 +30,6 @@ public class Switch : Activity
{
}
/// <summary>
/// The value to switch on.
/// </summary>
[Input(Description = "The value to switch on.")]
public Input<object> Expression { get; set; } = default!;
/// <summary>
/// The value to switch on, made available as output for capturing.
/// </summary>
@ -64,10 +58,8 @@ public class Switch : Activity
/// <inheritdoc />
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
context.Set(Output, Expression);
var matchingCases = await FindMatchingCasesAsync(context.ExpressionExecutionContext);
var matchingCases = (await FindMatchingCasesAsync(context.ExpressionExecutionContext)).ToList();
var hasAnyMatches = matchingCases.Any();
var mode = context.Get(Mode);
var results = mode == SwitchMode.MatchFirst ? hasAnyMatches ? new[] { matchingCases.First() } : Array.Empty<SwitchCase>() : matchingCases.ToArray();