Update ForEach to not store a copy of the list

Instead, rely on the Items property being set before each new iteration (which happens by default)
This commit is contained in:
Sipke Schoorstra 2021-02-11 11:01:57 +01:00
parent 040e132725
commit e3bb394a03

View file

@ -18,13 +18,7 @@ namespace Elsa.Activities.ControlFlow
{
[ActivityProperty(Hint = "Enter an expression that evaluates to a collection of items to iterate over.")]
public ICollection<object> Items { get; set; } = new Collection<object>();
private IList<object>? ItemsCopy
{
get => GetState<IList<object>>();
set => SetState(value);
}
private int? CurrentIndex
{
get => GetState<int?>();
@ -33,11 +27,7 @@ namespace Elsa.Activities.ControlFlow
protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context)
{
var collection = ItemsCopy;
if (collection == null)
ItemsCopy = collection = Items.ToList();
var collection = Items.ToList();
var currentIndex = CurrentIndex ?? 0;
if (currentIndex < collection.Count)
@ -49,7 +39,6 @@ namespace Elsa.Activities.ControlFlow
}
CurrentIndex = null;
ItemsCopy = null;
return Done();
}
}