Workflow 4.0 and System.Attribute
workflows seem to be created straight from Xaml. How then is would it be possible to include a System.Attribute on my workflow classes?
The only ways i can think of are a bit crap:
Have a corresponding code file for each Activity.xaml:
[MyCustomAttribute("hello")]
public abstract class MyPointlessWorkflowBase : System.Activity
{
}
And then having my .xaml inherit from the base (i don't even know if this is possible)? But this sucks as i have to an extra class for each Workflow that requires th开发者_运维技巧e attribute.
is there anyway to code activities like they were normal classes before you slap the .xaml over it?
A XAML file generates a class with a partial keyword before it gets compiled so you can create a partial class with the same name and add the attribute there.
[MyCustomAttribute("hello")]
public partial class MyWorkflow : Activity
{
}
Alternatively you can add an attribute in XAML using the x:ClassAttributes element and add them that way.
<p:Activity x:Class="WorkflowConsoleApplication1.MyWorkflow"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:my="......"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:ClassAttributes>
<my:MyCustomAttribute>
<x:Arguments>
<s:String>hello</s:String>
</x:Arguments>
</my:MyCustomAttribute>
</x:ClassAttributes>
</p:Activity>
精彩评论