0 out of 1 rated this helpful - Rate this topic

DynamicActivity Class

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

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

Namespace:  System.Activities
Assembly:  System.Activities (in System.Activities.dll)
[ContentPropertyAttribute("Implementation")]
public sealed class DynamicActivity : Activity, 
	ICustomTypeDescriptor

The DynamicActivity type exposes the following members.

  NameDescription
Public methodDynamicActivityCreates a new instance of the DynamicActivity class.
Top
  NameDescription
Public propertyAttributesGets the collection of attributes of the dynamically generated activity.
Protected propertyCacheIdGets the identifier of the cache that is unique within the scope of the workflow definition. (Inherited from Activity.)
Public propertyConstraintsReturns a collection of Constraint activities that are configured to provide validation for the DynamicActivity.
Public propertyDisplayNameGets or sets an optional friendly name that is used for debugging, validation, exception handling, and tracking. (Inherited from Activity.)
Public propertyIdGets an identifier that is unique in the scope of the workflow definition. (Inherited from Activity.)
Public propertyImplementationGets or sets the execution logic of the activity.
Public propertyImplementationVersionGets or sets the implementation version of the activity.
Public propertyNameThe name to be displayed for the activity in the workflow designer.
Public propertyPropertiesGets the collection of properties that map to the arguments of the dynamically generated activity.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodShouldSerializeDisplayNameIndicates whether the DisplayName property should be serialized. (Inherited from Activity.)
Public methodToStringReturns a String that contains the Id and DisplayName of the Activity. (Inherited from Activity.)
Top
  NameDescription
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetAttributesReturns a collection of attributes of the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetClassNameReturns the class name of the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetComponentNameReturns the component name of the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetConverterReturns a type converter for the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetDefaultEventReturns the default event for the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetDefaultPropertyReturns the default property for the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetEditorReturns an editor with the specified base type.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetEvents()Returns the collection of events of the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetEvents(Attribute[])Returns the collection of events of the dynamic activity using a specified array of attributes as a filter.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetProperties()Returns the collection of properties of the dynamic activity.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetProperties(Attribute[])Returns the collection of properties of the dynamic activity using a specified array of attributes as a filter.
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetPropertyOwnerReturns this instance of the DynamicActivity class.
Top

The following example shows how to create a DynamicActivity.

// 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>())
                },
            }
        }

.NET Framework

Supported in: 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.