I'd like to acheive "Truly Dynamic Runtime Activity Property Nirvana".
My most critical custom workflow activity needs to expose a list of items that is not known at custom activity compile time. Each item in the list can be bound to from other activities - this is a pretty powerful concept for our workflow application that makes it very useful for end users that design their own workflows with my custom activity. I've figured out a solution where this dynamic custom activity is possible but it involves dynamically generating / compiling a brand new custom activity class on the fly - not the prettiest solution and I'm trying to create a better solution.
Ghenadie has a neat example of how to create dynamic properties here http://blogs.msdn.com/ghenap/default.aspx but this only allows you to bind FROM the dynamic properties. I need to be able to bind TO the dynamic properties that don't exist in the custom activities class definition.
I've been trying to have a truly dynamic custom activity that contains properties that are not defined in the class definition of the activity. I'm very close to figuring out how to do this using PropertyDescriptors but unfortunately I've run up against a problem. The function ActivityBind.GetRuntimeValue eventually tries to resolve which activity and member that your trying to get data from when you run a workflow. Unfortunately, after the correct activity is resolved the WF code tries to find which member your trying to get data from with standard .NET reflection and ignores the TypeDescriptor. The PathWalker.TryWalkPropertyPath function is eventually called and this is where things break down. So, I can't figure out how to bind TO properties that don't actually exist in the class definition of a custom activity.
Anyone out there have any idea
Thanks

Truly Dynamic Runtime Activity Property Nirvana
Bdenison
Chakri,
Here's a really simple example of how to bind to a dynamic property. This example does NOT refer to ghenadie's example at all. It's just a very simple example.
This example won't run, but it has most of the necessary elements.
The magic happens here... new ActivityBind("ActivityWithDynamicData1", "Persons[\"Bill\"]");
The string \"Bill\" will be passed to the Dictionairy object called Persons. That's it in a nutshell. Good luck.
public class Person{
public string Name; public Person(string name){
Name = name;
}
}
public class ActivityWithDynamicData : Activity{
private Dictionary<string, Person> persons;[
Browsable(false)] public Dictionary<string, Person> Persons{
get { return persons; }}
public ActivityWithDynamicData(){
persons[
"Bill"] = new Person("Bill");persons[
"Jon"] = new Person("Jon");}
}
public class TestHarness{
static public void Test(){
ActivityBind activityBind = new ActivityBind("ActivityWithDynamicData1", "Persons[\"Bill\"]"); Person bill = (Person) activityBind.GetRuntimeValue(activityWithDynamicData);}
}
thomaskremmel
Hi,
Can you give me sample snippet for using DyanamicPropertyActivity in XAML only workflows.
Thanks & Regards,
Chakri.
nil130180
hey 0xDEADBEEF,
I did indeed find nothing in the API documentation, but i got a lot wiser by using reflector (isn't that tool brilliant )
Take a look at System.Workflow.ComponentModel.MemberBind.GetMemberInfo(). I haven't investigated it in detail, but i think the key is the PathWalker object: check if this one supports methods with 2 arguments.
Chakri, I guess that by editting the xaml for xml only flows, the same effect can be achieved...
daaboots
Thanks for the help Pros Van Dessel,
I'll try that out that trick you've shown.
mohadcs
Thanks a bunch Pros Van Dessel,
I had no idea that you could pass an arguement to a returned property like that. It makes my code much cleaner now.
How did you figure that out It's not in the api documentation.
I tried to bind to a function with 2 string parameters but couldn't get it to work - is it possible to bind to / evaluate functions with parameters as well
Thanks again,
hr0nix
your trick is simply superb Mr. Pros Van Dessel.
Can you please tell me how to do this binding through XAML only workflows.
-Chakri.
jkushiner
Pros Van Dessel,
Wow, great job with the reflector! I reflected into the function PathWalker.TryWalkPath a few weeks ago but I couldn't figure out what that big nasty function was doing. Great job!!!
BTW, I probably could have figured out the PathWalker.TryWalkPath if I had been able to actually debug into the WF source code. Any idea how to do that. I think I would need the debug dlls and the .pdb files but I'm not sure how to get them. Getting the source is easy via the reflector but the debug binaries are more tricky to come by :(
Luis Miguel Abreu
Hi,
Can you please provde the example to show how to u use dynamic properties.
-Chakri.
sea2006
I've encountered the same issue. The solution is actually quite easy:
Suppose you use the DynamicPropertiesActivity from the example of Ghenadie in a workflow and you have created a dynamic poperty of type 'Integer' with name 'DynamicInt'. Suppose you added a second activity 'SomeFixedActivity', with a fixed dependency property of type System.Int32. You can bind to the dynamic property by manually editing the workflowx.designer.cs code (where all bindings are generated):
activitybind1.Name = "dynamicPropertiesActivity"; // The name of the source activity (a DynamicPropertiesActivity)
activitybind1.Path = "ParameterBindings[\"DynamicInt\"].Value"; //This is the trick: access the ParameterBindings property
this.someFixedActivity1.Name = "someFixedActivity1";
this.someFixedActivity1.SetBinding(DynamicPropertyActivityLibrary.SomeFixedActivity.IntProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1)));
The trick is to directly access WorkflowParameterBindingCollection.
I' don't know if this technique can be concidered as a 'best practice' to bind to dynamic properties...