Atlas Control Toolkit and the DefaultValue attribute

Suppose your working on a new extender control using the Atlas Control toolkit that has been released (and recently updated with some more controls).

When you create a new set of classes using the extender template, you get an ExtenderProperties class that represents the attributes/properties of your extender control. You can specify the properties that your extender uses, and you can specify a DefaultValue attribute to indicate what the default value of a particular property is. An example is shown below:

[DefaultValue("SomeValue")]
public string
SomeProperty
{
  get
  {
    return
GetPropertyStringValue("SomeProperty");
  }
  set
  {
    SetPropertyStringValue("SomeProperty",
value
);
  }
}

Now, I mistakenly thought that the DefaultValue attribute indicates that if no value is specified for this property, then the value of "SomeValue" will be used.

What it in fact indicates to the runtime, but does not set, is what the initial state of the property will be in when no value is specified. In effect, this tells the serializer that if the value of the property matches what is specified in the DefaultValue attribute, then dont bother serializing this as there is no need. Also, if no value for this property is set (in the markup for example), then obviously nothing will be serialized for this, but it implies that the setting of this property when nothing has been explicitly set will be done in the script portion of the control. Furthermore, the script portion will be setting the default value of the property, to what you have specified in the DefaultValue attribute.

The DefaultValue attribute does not set the value of this property, it is used to match against for the purposes of serialization.

So dont assume that the DefaultValue attribute will provide any default values for your properties. It is just an indicator as to what IS the default value, and your script code should provide the logic to implement this. The DefaultValue attribute will be used by the serializer for optimization purposes.

3 Comments

  • Bully for you Thomas.



    Its an implied behavior that I think is understandably mis-interpreted. The fact that you didn't do it is not reason enough for others not to mis-interpret it without realising.



    But I do appreciate your positive comments.

  • I'm with you on this Paul, the property name could be clearer.



  • Hi Thomas,



    The quote from the documentation you provided seems to help my point of view, not undermine it.



    Whether you believe so or not is not the issue here (not that your point of view is not valid), the fact that others find it confusing is enough.



    I am glad you did not find it confusing, but I think this issue is done.

Comments have been disabled for this content.