Condividi tramite


Using Rules with Workflow Markup

When using rules or rule conditions in workflow markup, you must use GetActivityByName to reference child activities in the workflow. For example, if you have a custom activity named myCustomActivity with an int property named Foo, then using Foo in a rule condition would look like the following:

((myCustomActivityType)(this.GetActivityByName("myCustomActivity"))).Foo > 10

Note

The GetActivityByName method returns an Activity type, so you must cast it to the proper type to access its properties.

In a code-separation file, the activities are defined as properties on the workflow so the rule can directly access them in the following manner:

this.myCustomActivity.Foo > 10

Child activities of WhileActivity and ReplicatorActivity activities must be accessed differently because each iteration of the WhileActivity activity and every child activity created by the ReplicatorActivity activity exists in its own context. What this means is that the activity you receive from System.Workflow.Activities.ReplicatorActivity.DynamicActivities or System.Workflow.Activities.WhileActivity.DynamicActivity is from the workflow's context, which is a different instance of that child activity. To get the actual instance that is running, you must use the GetActivityByName method, as shown in the following example.

((myCustomActivity)(this.GetActivtyByName("instanceOfCustomActivity", true))).Foo > 5

The second parameter specifies if you want the child from the workflow context, or the child from the instance context. Because you want the instance that is running inside the WhileActivity or ReplicatorActivity, you should set the parameter to true.

See Also

Concepts

Using Workflow Markup