IgorShare Thoughts and Ideas

Consulting and Training

How to find all Workflows in an assembly

Posted by Igor Moochnick on 01/28/2008

This is a beginning of series of articles on workflows discoverablity and automation.

It’s easy to start a workflow if you know it’s type:

   1: WorkflowRuntime runtime = new WorkflowRuntime();
   2: runtime.StartRuntime();
   4: WorkflowInstance workflow = runtime.CreateWorkflow(typeof(MyWorkflowType), parms);

But what if you have an assembly and you don’t know a workflow type? Reflection is the answer. This is how you can find all the types in an assembly that inherit from an Activity (base type for all workflows) type:

   1: public static IEnumerable<Type> FindWorkflows(Assembly asm)
   2: {
   3:     return from t in asm.GetTypes()
   4:            where t.IsSubclassOf(typeof(Activity))
   5:            select t;
   6: }
   8: [TestMethod]
   9: public void FindAllWorkflowsInAssembly()
  10: {
  11:     foreach (Type t in WFHelper.FindWorkflows(WFHelper.LoadWorkflowAssembly(assembly_path)))
  12:     {
  13:         System.Diagnostics.Trace.WriteLine(t.Name);
  14:     }
  15: }

Note: the list, returned by FindWorfklows function, will contain all Custom activities in the provided assembly as well.

If you want to know how to narrow down the list, stay tuned.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: