/// <summary>
/// Initializes a specific property for this object.
/// </summary>
/// <param name="name">Name of the property.</param>
/// <param name="type">Type of the property.</param>
/// <param name="defaultValue">Default value of the property.</param>
/// <param name="propertyChangedEventHandler">The property changed event handler.</param>
/// <param name="isSerializable">if set to <c>true</c>, the property is serializable.</param>
/// <param name="includeInSerialization">if set to <c>true</c>, the property should be included in the serialization.</param>
/// <param name="includeInBackup">if set to <c>true</c>, the property should be included in the backup when handling IEditableObject.</param>
/// <param name="isModelBaseProperty">if set to <c>true</c>, the property is declared by the <see cref="ModelBase"/>.</param>
/// <param name="lateRegistration">if set to <c>true</c>, the property is assumed to be registered after the official initialization.</param>
/// <param name="isCalculatedProperty">if set to <c>true</c>, the property is a calculated property.</param>
/// <exception cref="InvalidPropertyException">The <paramref name="name"/> is <c>null</c> or whitespace.</exception>
/// <exception cref="PropertyAlreadyRegisteredException">The property is already registered.</exception>
private void InitializeProperty(string name, Type type, object defaultValue, EventHandler <AdvancedPropertyChangedEventArgs> propertyChangedEventHandler,
bool isSerializable, bool includeInSerialization, bool includeInBackup, bool isModelBaseProperty, bool lateRegistration, bool isCalculatedProperty)
{
var objectType = GetType();
if ((defaultValue is null) && !type.IsNullableType())
{
throw Log.ErrorAndCreateException(msg => new PropertyNotNullableException(name, objectType),
"Property '{0}' is not nullable, please provide a valid (not null) default value", name);
}
if (!IsPropertyRegistered(name))
{
var propertyData = new PropertyData(name, type, defaultValue, propertyChangedEventHandler,
isSerializable, includeInSerialization, includeInBackup, isModelBaseProperty, isCalculatedProperty);
PropertyDataManager.RegisterProperty(objectType, name, propertyData);
}
lock (_lock)
{
if (!_propertyBag.IsPropertyAvailable(name))
{
SetValueToPropertyBag(name, defaultValue);
}
}
}