|
|
@ -29,7 +29,12 @@ namespace Perspex |
|
|
private static int s_nextId = 1; |
|
|
private static int s_nextId = 1; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// The default values for the property, by type.
|
|
|
/// The default value provided when the property was first registered.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly object _defaultValue; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The overridden default values for the property, by type.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private readonly Dictionary<Type, object> _defaultValues = new Dictionary<Type, object>(); |
|
|
private readonly Dictionary<Type, object> _defaultValues = new Dictionary<Type, object>(); |
|
|
|
|
|
|
|
|
@ -93,7 +98,7 @@ namespace Perspex |
|
|
Name = name; |
|
|
Name = name; |
|
|
PropertyType = valueType; |
|
|
PropertyType = valueType; |
|
|
OwnerType = ownerType; |
|
|
OwnerType = ownerType; |
|
|
_defaultValues.Add(ownerType, defaultValue); |
|
|
_defaultValue = defaultValue; |
|
|
Inherits = inherits; |
|
|
Inherits = inherits; |
|
|
DefaultBindingMode = defaultBindingMode; |
|
|
DefaultBindingMode = defaultBindingMode; |
|
|
IsAttached = isAttached; |
|
|
IsAttached = isAttached; |
|
|
@ -144,14 +149,57 @@ namespace Perspex |
|
|
/// Initializes a new instance of the <see cref="PerspexProperty"/> class.
|
|
|
/// Initializes a new instance of the <see cref="PerspexProperty"/> class.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="source">The direct property to copy.</param>
|
|
|
/// <param name="source">The direct property to copy.</param>
|
|
|
|
|
|
/// <param name="ownerType">The new owner type.</param>
|
|
|
|
|
|
protected PerspexProperty(PerspexProperty source, Type ownerType) |
|
|
|
|
|
{ |
|
|
|
|
|
Contract.Requires<ArgumentNullException>(source != null); |
|
|
|
|
|
Contract.Requires<ArgumentNullException>(ownerType != null); |
|
|
|
|
|
|
|
|
|
|
|
if (source.IsDirect) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new InvalidOperationException( |
|
|
|
|
|
"This method cannot be called on direct PerspexProperties."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Name = name;
|
|
|
|
|
|
//PropertyType = valueType;
|
|
|
|
|
|
//OwnerType = ownerType;
|
|
|
|
|
|
//_defaultValues.Add(ownerType, defaultValue);
|
|
|
|
|
|
//Inherits = inherits;
|
|
|
|
|
|
//DefaultBindingMode = defaultBindingMode;
|
|
|
|
|
|
//IsAttached = isAttached;
|
|
|
|
|
|
//Notifying = notifying;
|
|
|
|
|
|
//_id = s_nextId++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Name = source.Name; |
|
|
|
|
|
PropertyType = source.PropertyType; |
|
|
|
|
|
OwnerType = ownerType; |
|
|
|
|
|
_defaultValue = source._defaultValue; |
|
|
|
|
|
_defaultValues = source._defaultValues; |
|
|
|
|
|
Inherits = source.Inherits; |
|
|
|
|
|
DefaultBindingMode = source.DefaultBindingMode; |
|
|
|
|
|
IsAttached = false; |
|
|
|
|
|
Notifying = Notifying; |
|
|
|
|
|
_validation = source._validation; |
|
|
|
|
|
_id = source._id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="PerspexProperty"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="source">The direct property to copy.</param>
|
|
|
|
|
|
/// <param name="ownerType">The new owner type.</param>
|
|
|
/// <param name="getter">A new getter.</param>
|
|
|
/// <param name="getter">A new getter.</param>
|
|
|
/// <param name="setter">A new setter.</param>
|
|
|
/// <param name="setter">A new setter.</param>
|
|
|
protected PerspexProperty( |
|
|
protected PerspexProperty( |
|
|
PerspexProperty source, |
|
|
PerspexProperty source, |
|
|
|
|
|
Type ownerType, |
|
|
Func<PerspexObject, object> getter, |
|
|
Func<PerspexObject, object> getter, |
|
|
Action<PerspexObject, object> setter) |
|
|
Action<PerspexObject, object> setter) |
|
|
{ |
|
|
{ |
|
|
Contract.Requires<ArgumentNullException>(source != null); |
|
|
Contract.Requires<ArgumentNullException>(source != null); |
|
|
|
|
|
Contract.Requires<ArgumentNullException>(ownerType != null); |
|
|
Contract.Requires<ArgumentNullException>(getter != null); |
|
|
Contract.Requires<ArgumentNullException>(getter != null); |
|
|
|
|
|
|
|
|
if (!source.IsDirect) |
|
|
if (!source.IsDirect) |
|
|
@ -162,7 +210,7 @@ namespace Perspex |
|
|
|
|
|
|
|
|
Name = source.Name; |
|
|
Name = source.Name; |
|
|
PropertyType = source.PropertyType; |
|
|
PropertyType = source.PropertyType; |
|
|
OwnerType = source.OwnerType; |
|
|
OwnerType = ownerType; |
|
|
Getter = getter; |
|
|
Getter = getter; |
|
|
Setter = setter; |
|
|
Setter = setter; |
|
|
IsDirect = true; |
|
|
IsDirect = true; |
|
|
@ -530,7 +578,7 @@ namespace Perspex |
|
|
type = type.GetTypeInfo().BaseType; |
|
|
type = type.GetTypeInfo().BaseType; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return _defaultValues[OwnerType]; |
|
|
return _defaultValue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
|