다음을 통해 공유


WF의 컬렉션 활동

이 항목은 Windows Workflow Foundation 4에 적용됩니다.

컬렉션 활동은 워크플로에서 컬렉션 개체로 작업하는 데 사용됩니다. .NET Framework 버전 4에는 컬렉션에서 항목을 추가 및 제거하고, 컬렉션에 항목이 있는지 테스트하고, 컬렉션을 지우는 시스템 제공 활동이 있습니다. 모든 컬렉션 활동은 CodeActivity 또는 CodeActivity에서 상속되는 제네릭 클래스이고 ExistsInCollectionRemoveFromCollection에는 결과를 나타내는 Boolean 형식의 OutArgument이 있습니다.

Ee358729.Important(ko-kr,VS.100).gif 참고:
기본 컬렉션 개체를 설정하기 이전에 컬렉션 활동을 실행하면 InvalidOperationException이 throw되고 활동 오류가 발생합니다.

컬렉션 활동

AddToCollection

지정한 컬렉션에 항목을 추가합니다.

ClearCollection

지정한 컬렉션에서 모든 항목을 지웁니다.

ExistsInCollection

항목이 컬렉션에 있으면 true를 반환합니다.

RemoveFromCollection

지정된 컬렉션에서 항목을 제거한 후 항목이 성공적으로 제거되면 true를 반환합니다.

컬렉션 활동 사용

다음 코드 예제에서는 워크플로 변수로 선언된 컬렉션과 상호 작용하는 방법을 보여 줍니다. 사용된 컬렉션은 fruitList라는 String 개체의 List’1입니다.

Variable<ICollection<string>> fruitList = new Variable<ICollection<string>>
{
Default = new List<string>
      {
          "Apple",
          "Orange",
      },
      Name = "FruitList",
};

Variable<bool> result = new Variable<bool>
{
      Name = "Result",
}

Sequence seq1 = new Sequence
{
    Variables = { fruitList, result },

    Activities = 
    {
        new If
        {
        Condition = new ExistsInCollection<string>
            {
                Collection = fruitList,
                Item = "Pear",
            },
            Then = new AddToCollection<string>
            {
                Collection = fruitList,
                Item = "Pear",
            },
            Else = new RemoveFromCollection<string>
            {
               Collection = fruitList,
               Item = “Apple”,
            },

        new RemoveFromCollection<string>
        {
            Collection = fruitList,
            Item = "Apple",
            Result = result,
        },
        new If
        {
            Condition = result,
            Then = new ClearCollection<string>
            {
                Collection = fruitList,
            }
        }
    }
 };
<Sequence xmlns="https://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
  <Sequence.Variables>
    <Variable x:TypeArguments="scg:ICollection(x:String)" Name="FruitList">
      <Variable.Default>
        <Literal x:TypeArguments="scg:ICollection(x:String)" Result="{x:Null}">
          <scg:List x:TypeArguments="x:String" Capacity="4">
            <x:String>Orange</x:String>
          </scg:List>
        </Literal>
      </Variable.Default>
    </Variable>
    <Variable x:TypeArguments="x:Boolean" Name="Result" />
  </Sequence.Variables>
  <If>
    <If.Condition>
      <InArgument x:TypeArguments="x:Boolean">
        <ExistsInCollection x:TypeArguments="x:String" Item="Pear" Result="{x:Null}">[FruitList]</ExistsInCollection>
      </InArgument>
    </If.Condition>
    <If.Else>
     <RemoveFromCollection x:TypeArguments="x:String" Item="Apple" Result="{x:Null}">[FruitList]</RemoveFromCollection>
    </If.Else>
    <If.Then>
      <AddToCollection x:TypeArguments="x:String" Item="Pear">[FruitList]</AddToCollection>
    </If.Then>
  </If>
  <RemoveFromCollection x:TypeArguments="x:String" Item="Apple" Result="[Result]">[FruitList]</RemoveFromCollection>
  <If Condition="[Result]">
    <If.Then>
      <ClearCollection x:TypeArguments="x:String">[FruitList]</ClearCollection>
    </If.Then>
  </If>
</Sequence>