/// <summary>
 /// Returns the type of a specific property.
 /// </summary>
 /// <param name="property"><see cref="PropertyData"/> of the property.</param>
 /// <returns>Type of the property.</returns>
 /// <exception cref="PropertyNotRegisteredException">The property is not registered.</exception>
 Type IModel.GetPropertyType(PropertyData property)
 {
     return(((IModel)this).GetPropertyType(property.Name));
 }
 /// <summary>
 /// Initializes a specific property for this object.
 /// </summary>
 /// <param name="property">The property.</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="ArgumentNullException">The <paramref name="property" /> is <c>null</c>.</exception>
 /// <exception cref="InvalidPropertyException">The name of the property is invalid.</exception>
 /// <exception cref="PropertyAlreadyRegisteredException">The property is already registered.</exception>
 private void InitializeProperty(PropertyData property, bool lateRegistration = false, bool isCalculatedProperty = false)
 {
     InitializeProperty(property.Name, property.Type, property.GetDefaultValue(), property.SetParent, property.PropertyChangedEventHandler,
                        property.IsSerializable, property.IncludeInSerialization, property.IncludeInBackup, property.IsModelBaseProperty, lateRegistration, isCalculatedProperty);
 }
 /// <summary>
 /// Gets the <see cref="PropertyInfo"/> for the specified property.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns><see cref="PropertyInfo"/> or <c>null</c> if no property info is found.</returns>
 protected PropertyInfo GetPropertyInfo(PropertyData property)
 {
     return(GetPropertyInfo(property.Name));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldValidationResult"/> class.
 /// </summary>
 /// <param name="property">The property data.</param>
 /// <param name="validationResultType">Type of the validation result.</param>
 /// <param name="messageFormat">The message format.</param>
 /// <param name="args">The args.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="property"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">The <paramref name="messageFormat"/> is <c>null</c> or whitespace.</exception>
 public FieldValidationResult(PropertyData property, ValidationResultType validationResultType, string messageFormat, params object[] args)
     : this(property.Name, validationResultType, messageFormat, args)
 {
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyValue"/> class.
 /// </summary>
 /// <param name="propertyData">The property data.</param>
 /// <param name="keyValuePair">The key value pair.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="propertyData"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">The <c>Key</c> of <paramref name="keyValuePair"/> is <c>null</c> or whitespace.</exception>
 public PropertyValue(PropertyData propertyData, KeyValuePair <string, object> keyValuePair)
     : this(propertyData, keyValuePair.Key, keyValuePair.Value)
 {
 }
        /// <summary>
        /// Sets the value of a specific property.
        /// </summary>
        /// <param name="property">The property to set.</param>
        /// <param name="value">Value of the property.</param>
        /// <param name="notifyOnChange">If <c>true</c>, the <see cref="INotifyPropertyChanged.PropertyChanged"/> event will be invoked.</param>
        /// <param name="validateAttributes">If set to <c>true</c>, the validation attributes on the property will be validated.</param>
        /// <exception cref="PropertyNotNullableException">The property is not nullable, but <paramref name="value"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="property"/> is <c>null</c>.</exception>
        internal void SetValue(PropertyData property, object value, bool notifyOnChange, bool validateAttributes)
        {
            Argument.IsNotNull("property", property);

            // Is the object currently read-only (and aren't we changing that)?
            if (IsReadOnly)
            {
                if (property != IsReadOnlyProperty)
                {
                    Log.Warning("Cannot set property '{0}', object is currently read-only", property.Name);
                    return;
                }
            }

            if (property.IsCalculatedProperty)
            {
                Log.Warning("Cannot set property '{0}', the property is a calculated property", property.Name);
                return;
            }

            if (!LeanAndMeanModel)
            {
                if ((value != null) && !property.Type.IsInstanceOfTypeEx(value))
                {
                    if (!value.GetType().IsCOMObjectEx())
                    {
                        throw new InvalidPropertyValueException(property.Name, property.Type, value.GetType());
                    }
                }
            }

            lock (_propertyValuesLock)
            {
                var oldValue = GetValueFast(property.Name);
                var areOldAndNewValuesEqual = ObjectHelper.AreEqualReferences(oldValue, value);

                if (notifyOnChange && (AlwaysInvokeNotifyChanged || !areOldAndNewValuesEqual) && !LeanAndMeanModel)
                {
                    var propertyChangingEventArgs = new AdvancedPropertyChangingEventArgs(property.Name);
                    RaisePropertyChanging(this, propertyChangingEventArgs);

                    if (propertyChangingEventArgs.Cancel)
                    {
                        Log.Debug("Change of property '{0}.{1}' is canceled in PropertyChanging event", GetType().FullName, property.Name);
                        return;
                    }
                }

                // Validate before assigning, dynamic properties will cause exception
                if (validateAttributes && !LeanAndMeanModel)
                {
                    ValidatePropertyUsingAnnotations(property.Name, value, property);
                }

                if (!areOldAndNewValuesEqual)
                {
                    SetValueFast(property.Name, value);
                }

                if (notifyOnChange && (AlwaysInvokeNotifyChanged || !areOldAndNewValuesEqual) && !LeanAndMeanModel)
                {
                    RaisePropertyChanged(property.Name, oldValue, value);
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Sets the value of a specific property.
 /// </summary>
 /// <param name="property">The property to set.</param>
 /// <param name="value">Value of the property.</param>
 /// <param name="notifyOnChange">If <c>true</c>, the <see cref="INotifyPropertyChanged.PropertyChanged"/> event will be invoked.</param>
 /// <exception cref="PropertyNotNullableException">The property is not nullable, but <paramref name="value"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="property"/> is <c>null</c>.</exception>
 protected internal void SetValue(PropertyData property, object value, bool notifyOnChange = true)
 {
     SetValue <object>(property, value, notifyOnChange);
 }
        /// <summary>
        /// Sets the value of a specific property.
        /// </summary>
        /// <param name="property"><see cref="PropertyData"/> of the property.</param>
        /// <param name="value">Value of the property.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="property"/> is <c>null</c>.</exception>
        /// <exception cref="PropertyNotRegisteredException">The property is not registered.</exception>
        protected internal void SetValue(PropertyData property, object value)
        {
            Argument.IsNotNull("property", property);

            SetValue(property, value, true, true);
        }
        /// <summary>
        /// Returns the typed default value of a specific property.
        /// </summary>
        /// <typeparam name="TValue">The type of the 1.</typeparam>
        /// <param name="property"><see cref="PropertyData"/> of the property.</param>
        /// <returns>Default value of the property.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="property"/> is <c>null</c>.</exception>
        /// <exception cref="PropertyNotRegisteredException">The property is not registered.</exception>
        TValue IModel.GetDefaultValue <TValue>(PropertyData property)
        {
            Argument.IsNotNull("property", property);

            return(((IModel)this).GetDefaultValue <TValue>(property.Name));
        }
 /// <summary>
 /// Sets the value of a specific property.
 /// </summary>
 /// <param name="property"><see cref="PropertyData"/> of the property.</param>
 /// <param name="value">Value of the property.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="property"/> is <c>null</c>.</exception>
 /// <exception cref="PropertyNotRegisteredException">The property is not registered.</exception>
 protected internal void SetValue(PropertyData property, object value)
 {
     SetValue(property, value, true, true);
 }
Beispiel #11
0
 /// <summary>
 /// Gets the property value to use during deserialization.
 /// <para />
 /// This method allows the customization of the property value deserialization.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="serializedValue">The value that was serialized.</param>
 /// <returns>The value to deserialize.</returns>
 protected virtual object GetPropertyValueForDeserialization(PropertyData property, object serializedValue)
 {
     return(serializedValue);
 }
Beispiel #12
0
 /// <summary>
 /// Gets the property value to use during serialization.
 /// <para />
 /// This method allows the customization of property value serialization.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="propertyValue">The actual value of the property.</param>
 /// <returns>The value to serialize.</returns>
 protected virtual object GetPropertyValueForSerialization(PropertyData property, object propertyValue)
 {
     return(propertyValue);
 }