How to Iterate ArrayList in Business Rules

Switch View :
ScriptFree
How to Iterate ArrayList in Business Rules

This section provides an example of iterating through members of an ArrayList in business rules.

Assume you have an ArrayList with a collection of MyClass objects. Your business rules would look like the following.

Rule A

IF 1==1

THEN Assert (ArrayList.GetEnumerator)

An IEnumerator type is asserted into the working memory, because the rule condition (1==1) always evaluates to true.

Rule B

IF IEnumerator.MoveNext

THEN Assert (IEnumerator.get_Current)

Update (IEnumerator)

As the rule iterates through the ArrayList, each MyClass object in the collection is asserted into the working memory.

Rule C

IF MyClass.MyProperty==2

THEN <Do Something...>

This rule executes action(s) when the property value of the object is matched in the condition.

Community Content

Dan Rosanova
So where are ArrayList and IEnumerator?
You must add a class to the class explorer in the BRE to use ArrayList and IEnumerator.  Simply browse to mscorlib and be sure to use the 4.0 version when using BizTalk 2010.  From here you have access to all the core .NET classes. 

This same example also works by replacing ArrayList.GetEnumerator with IEnumerable.GetEnumerator which not only works with ArrayList, but also with generic collections as well (though these are more difficult to pass in from an orchestration without helper classes).