DynamicActivity Class (System.Activities)

Switch View :
ScriptFree
.NET Framework Class Library
DynamicActivity Class

Provides an object model that allows you to construct activities dynamically that interface with the WF designer and runtime using ICustomTypeDescriptor.

Inheritance Hierarchy

System.Object
  System.Activities.Activity
    System.Activities.DynamicActivity

Namespace:  System.Activities
Assembly:  System.Activities (in System.Activities.dll)
Syntax

Visual Basic
<ContentPropertyAttribute("Implementation")> _
Public NotInheritable Class DynamicActivity _
	Inherits Activity _
	Implements ICustomTypeDescriptor
C#
[ContentPropertyAttribute("Implementation")]
public sealed class DynamicActivity : Activity, 
	ICustomTypeDescriptor
Visual C++
[ContentPropertyAttribute(L"Implementation")]
public ref class DynamicActivity sealed : public Activity, 
	ICustomTypeDescriptor
F#
[<Sealed>]
[<ContentPropertyAttribute("Implementation")>]
type DynamicActivity =  
    class
        inherit Activity
        interface ICustomTypeDescriptor
    end

The DynamicActivity type exposes the following members.

Constructors

  Name Description
Public method DynamicActivity Creates a new instance of the DynamicActivity class.
Top
Properties

  Name Description
Public property Attributes Gets the collection of attributes of the dynamically generated activity.
Protected property CacheId Gets the identifier of the cache that is unique within the scope of the workflow definition. (Inherited from Activity.)
Public property Constraints Returns a collection of Constraint activities that are configured to provide validation for the DynamicActivity.
Public property DisplayName Gets or sets an optional friendly name that is used for debugging, validation, exception handling, and tracking. (Inherited from Activity.)
Public property Id Gets an identifier that is unique in the scope of the workflow definition. (Inherited from Activity.)
Public property Implementation Gets or sets the execution logic of the activity.
Public property Name The name to be displayed for the activity in the workflow designer.
Public property Properties Gets the collection of properties that map to the arguments of the dynamically generated activity.
Top
Methods

  Name Description
Protected method CacheMetadata Creates and validates a description of the activity’s arguments, variables, child activities, and activity delegates. (Inherited from Activity.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ShouldSerializeDisplayName Indicates whether the DisplayName property should be serialized. (Inherited from Activity.)
Public method ToString Returns a String that contains the Id and DisplayName of the Activity. (Inherited from Activity.)
Top
Explicit Interface Implementations

  Name Description
Explicit interface implemetation Private method ICustomTypeDescriptor.GetAttributes Returns a collection of attributes of the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetClassName Returns the class name of the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetComponentName Returns the component name of the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetConverter Returns a type converter for the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetDefaultEvent Returns the default event for the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetDefaultProperty Returns the default property for the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetEditor Returns an editor with the specified base type.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetEvents() Returns the collection of events of the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetEvents(Attribute[]) Returns the collection of events of the dynamic activity using a specified array of attributes as a filter.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetProperties() Returns the collection of properties of the dynamic activity.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetProperties(Attribute[]) Returns the collection of properties of the dynamic activity using a specified array of attributes as a filter.
Explicit interface implemetation Private method ICustomTypeDescriptor.GetPropertyOwner Returns this instance of the DynamicActivity class.
Top
Examples

The following example shows how to create a DynamicActivity.

C#

// Variables
var iterationVariable = new DelegateInArgument<int>() { Name = "iterationVariable" };
var accumulator = new Variable<int>() { Default = 0, Name = "accumulator" };

// Define the Input and Output arguments that the DynamicActivity binds to
var numbers = new InArgument<List<int>>();
var average = new OutArgument<double>();

var result = new Variable<double>() { Name = "result" };

return new DynamicActivity()
{
    DisplayName = "Find average",
    Properties = 
    {
        // Input argument
        new DynamicActivityProperty
        {
            Name = "Numbers",
            Type = typeof(InArgument<List<int>>),
            Value = numbers
        },
        // Output argument
        new DynamicActivityProperty
        {
            Name = "Average",
            Type = typeof(OutArgument<double>),
            Value = average
        }
    },
    Implementation = () =>
        new Sequence
        {
            Variables = { result, accumulator },
            Activities =
            {
                new ForEach<int>
                {
                    Values =  new ArgumentValue<IEnumerable<int>> { ArgumentName = "Numbers" },                                
                    Body = new ActivityAction<int>
                    {
                        Argument = iterationVariable,
                        Handler = new Assign<int>
                        {
                            To = accumulator,
                            Value = new InArgument<int>(env => iterationVariable.Get(env) +  accumulator.Get(env))
                        }
                    }
                },

                // Calculate the average and assign to the output argument.
                new Assign<double>
                {
                    To = new ArgumentReference<double> { ArgumentName = "Average" },
                    Value = new InArgument<double>(env => accumulator.Get(env) / numbers.Get(env).Count<int>())
                },
            }
        }


Version Information

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference