views:

19

answers:

1

I am using a List (Of String) in WF4 because I'd like to perform set operations (like get distinct, etc.) and had a qs. about using the AddToCollection activity. Is it possible to add a number of items with one statement? e.g. I'd like to add "alpha", "bravo", "charlie" in one activity instead of three

The Collection - String does not work well for me because I cannot get it in the C# call in the client. I could use that too if you have a solution.

Thanks in advance.

A: 

No, the built-in AddToCollection activity only supports adding one at a time. Most likely this is because it uses the IList interface which doesn't offer a method to add items in bulk unlike List which has AddRange. You should be able to write an AddManyToList activity very easily. Here's some sample code to get you goin:

public sealed class AddManyToList<T> : CodeActivity
{
    [RequiredArgument]
    public InArgument<List<T>> List
    {
       get;
       set;
    }

    [RequiredArgument]
    public InArgument<IEnumerable<T>> Items
    {
       get;
       set;
    }

    public override void Execute(CodeActivityContext context)
    {
       this.List.Get(context).AddRange(this.Items.Get(context))
    }
}
Drew Marsh