I have created a couple of custom workflow activities for SharePoint 2007 and they are working. However, I find that my custom activities share a lot of properties/methods and so I have attempted to make an inheritance structure that makes sense. Everything works like you would expect, almost.
For example, I have a logging function that I use in nearly every custom activity I write. In my base class I have:
Protected Sub Log(ByVal IsError As Boolean, ByVal Message As String, Optional ByVal AlwaysLog As Boolean = False) If AlwaysLog OrElse VerboseLogging Then WorkflowLogger.LogEvent(__ActivationProperties, IsError, Message) End If End Sub
There are 2 properties,
VerboseLogging, that have to be set by the workflow for this to work. If this were the activity (not just a base class) I would declare them like this:
Public Shared __ActivationPropertiesProperty As DependencyProperty = DependencyProperty.Register("__ActivationProperties", GetType(SPWorkflowActivationProperties), GetType(LoggingActivity)) <Browsable(True)> _ <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _ <ValidationOption(ValidationOption.Required)> _ Public Overrides Property __ActivationProperties() As SPWorkflowActivationProperties Get Return (CType((MyBase.GetValue(LoggingActivity.__ActivationPropertiesProperty)), SPWorkflowActivationProperties)) End Get Set(ByVal Value As SPWorkflowActivationProperties) MyBase.SetValue(LoggingActivity.__ActivationPropertiesProperty, Value) End Set End Property Public Shared VerboseLoggingProperty As DependencyProperty = DependencyProperty.Register("VerboseLogging", GetType(Boolean), GetType(LoggingActivity)) <Browsable(True)> _ <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _ Public Overrides Property VerboseLogging() As Boolean Get Return (CType((MyBase.GetValue(LoggingActivity.VerboseLoggingProperty)), Boolean)) End Get Set(ByVal Value As Boolean) MyBase.SetValue(LoggingActivity.VerboseLoggingProperty, Value) End Set End Property
This works if the above dependencyproperty registration takes place in the class I am using, however, if I inherit from this class (the registration takes place in the base class) the properties are never set. This is true for all types of properties not just the example above.
For now I have resorted to adding this to my base class:
MustOverride Property __ActivationProperties() As SPWorkflowActivationProperties MustOverride Property VerboseLogging() As Boolean
Then in EACH derived class I have to override those properties and provide dependencyproperty registration using the specific derived class type.
I have tried several different variations of the dependencyproperty code to try and make it generic and work with my derived classes but I am at a loss. Anyone have any experience with this? My workaround is better than redeclaring everything, but not much better. The code above is VB.NET but solutions/examples in C# are just fine. Thanks in Advance.
This question was manually migrated from StackOverflow (SharePoint Custom Activity Dependency Property Inheritance) where it earned me the Tumbleweed Badge - surely we can do better!