Open.Core.ModelBase.Set C# (CSharp) Method

Set() protected method

Stores the given value for the named property (firing the 'PropertyChanged' event if the value differs from the current value).
protected Set ( string propertyName, object value, object defaultValue ) : bool
propertyName string The name of the property.
value object The value to set.
defaultValue object The default value of the property.
return bool
        protected bool Set(string propertyName, object value, object defaultValue)
        {
            // Setup initial conditions.
            if (Script.IsNullOrUndefined(value)) value = null;

            // Don't continue if the value has not changed.
            object currentValue = Get(propertyName, defaultValue);
            if (value == currentValue) return false;

            // Store value and fire event.
            PropertyBag[propertyName] = value;
            FirePropertyChanged(propertyName);

            // Finish up.
            return true;
        }