This project has moved and is read-only. For the latest updates, please go here.

Has Custom Attributes

Nov 8, 2012 at 6:21 PM
Edited Nov 8, 2012 at 6:23 PM

Firstly, thanks for a great, great extension!

I have been using your work to allow for the definition of a number of strategies for an algorithm. The problem is that some of the strategies require additional parameters to work (e.g. a ProbabilisticStrategy requires a probability value to be initialized with). Since this is supposed to be an extensible framework, I don’t know the names of all the possible parameters, and therefore could not define them as optional attributes.

I initially solved this by utilizing the 'Has Custom Child Elements' property in ConfigurationElement which led to a configuration that looked like this:

<Strategy type="StandardStrategy" />
<Strategy type="ProbabilisticStrategy">

However I was not totally happy about it, because what I would have preferred is something like this:

<Strategy type="StandardStrategy" />
<Strategy type="ProbabilisticStrategy" probability="0.8" />

After looking at the generated code and the documentation I discovered that there exists a OnDeserializeUnrecognizedAttribute overridable method which does for attributes what OnDeserializeUnrecognizedElement does for elements. So, by overriding that method I could do exactly what I was looking for, albeit in a code-only non-designer-based way.


So, to get to the point, would it be easy to add a ‘Has Custom Attributes’ option to the ConfigurationElement designer that would work the same way that 'Has Custom Child Elements' works right now but for attributes? Or is there some hidden gotcha that I’m not aware of? (I guess it would pretty much be a copy-paste of the 'Has Custom Child Element' implementation, but then again I have not done any code generation programming, so just correct me if I’m wrong.)