public object PropertyValue {
get {
if (needPropertyValue) {
- propertyValue = GetDeserializedValue ();
- if (propertyValue == null) {\r
- if (!property.PropertyType.IsAssignableFrom (property.DefaultValue.GetType ())) {\r
- TypeConverter converter = TypeDescriptor.GetConverter (property.PropertyType);\r
- propertyValue = converter.ConvertFrom (property.DefaultValue);\r
- }\r
- else {\r
- propertyValue = property.DefaultValue;\r
- }
+ propertyValue = GetDeserializedValue (serializedValue);
+ if (propertyValue == null) {
+ propertyValue = GetDeserializedDefaultValue ();
defaulted = true;
}
needPropertyValue = false;
}
-#if notyet
- /* LAMESPEC: the msdn2 docs say that
- * for object types this
- * pessimistically sets Dirty == true.
- * tests, however, point out that that
- * is not the case. */
- if (!property.PropertyType.IsValueType)
+ if (propertyValue != null &&
+ !(propertyValue is string) &&
+ !(propertyValue is DateTime) &&
+ !property.PropertyType.IsPrimitive)
dirty = true;
-#endif
return propertyValue;
}
}
}
- private object GetDeserializedValue ()
+ private object GetDeserializedDefaultValue ()
+ {
+ if (property.DefaultValue == null)
+ if (property.PropertyType.IsValueType)
+ return Activator.CreateInstance (property.PropertyType);
+ else
+ return null;
+
+ if (property.DefaultValue is string && ((string) property.DefaultValue).Length == 0)
+ if (property.PropertyType != typeof (string))
+ return Activator.CreateInstance (property.PropertyType);
+ else
+ return string.Empty;
+
+ if (property.DefaultValue is string && ((string) property.DefaultValue).Length > 0)
+ return GetDeserializedValue (property.DefaultValue);
+
+ if (!property.PropertyType.IsAssignableFrom (property.DefaultValue.GetType ())) {
+ TypeConverter converter = TypeDescriptor.GetConverter (property.PropertyType);
+ return converter.ConvertFrom (property.DefaultValue);
+ }
+ return property.DefaultValue;
+ }
+
+ private object GetDeserializedValue (object serializedValue)
{
if (serializedValue == null)
return null;
try {
switch (property.SerializeAs) {
case SettingsSerializeAs.String:
- if (((string) serializedValue).Length > 0)
+ if (serializedValue is string && ((string) serializedValue).Length > 0)
deserializedObject = TypeDescriptor.GetConverter (property.PropertyType).ConvertFromString ((string) serializedValue);
break;
#if (XML_DEP)
return deserializedObject;
}
- SettingsProperty property;
+ readonly SettingsProperty property;
object propertyValue;
object serializedValue;
bool needSerializedValue;