1

Closed

Change the type of the DefaultValue property of PageTypePropertyAttribute from string to object

description

I believe it would be better to have the DefaultValue property the PageTypePropertyAttribute as an object rather than string. That way you can use the same constants when returning a default value in the code as when specifying the DefaultValue for the property.
The default value string can be retrieved by using ToString() on the DefaultValue object.
Closed Apr 21, 2010 at 5:57 PM by joelabrahamsson
Fixed in 1.2 beta 2, sorry for the delay

comments

joelabrahamsson wrote Dec 10, 2009 at 7:43 PM

I'm afraid that that wont work as the value has to be a constant. Will give it a try when I have the time though.

henriknystrom wrote Dec 10, 2009 at 11:30 PM

I think you misunderstood me then, I've already done this change in my local version of PTB:
In PageTypePropertyAttribute:
public object DefaultValue { get; set; }

In PageTypePropertyUpdater.UpdatePageDefinitionValues one line is changed to:
pageDefinition.DefaultValue = propertyAttribute.DefaultValue != null ? propertyAttribute.DefaultValue.ToString() : string.Empty;

The type of the constant is exactly the reason why I want this to be changed.

I'll give you an example:
In my code I have a constant describing the default value of a property that is, say an integer describing the max items in a list. If the property is not set I return this constant.
To help the editors I want this value to be the default value of the property as well. Since the DefaultValue of PageTypePropertyAttribute currently is a string I would have to create two constants for this scenario, one integer and one string.
const string MaxItemsDefaultPropertyValue = "10";
const int MaxItemsDefaultValue = 10;

wrote Apr 18, 2010 at 7:39 PM

wrote Apr 21, 2010 at 5:57 PM

wrote Feb 14, 2013 at 7:04 PM

wrote May 16, 2013 at 8:34 AM