Ejemplo n.º 1
0
        /// <summary>
        ///     Helper method to update the DefaultableValue if and only if the value has changed
        /// </summary>
        /// <param name="existingValue">
        ///     existing value of attribute (StringOrNone.NoneValue indicates attribute
        ///     currently does not exist)
        /// </param>
        /// <param name="newValue">
        ///     new value of attribute passed into setter (null indicates user did not select
        ///     anything on the drop-down and so no setting should take place, StringOrNone.NoneValue indicates user
        ///     selected '(None)' on the drop-down and so attribute should be removed if present)
        /// </param>
        /// <param name="defaultableValueToUpdate"></param>
        internal static void UpdateDefaultableValueIfValuesDiffer(
            StringOrNone existingValue, StringOrNone newValue,
            DefaultableValue <StringOrNone> defaultableValueToUpdate)
        {
            if (null == newValue)
            {
                // user exited drop-down without selecting anything
                return;
            }

            if (existingValue.Equals(newValue))
            {
                // no change in value - so just return
                return;
            }
            else
            {
                // existingValue and valueToSet are different - so update the DefaultableValue
                // if newValue is NoneValue then set valueToSet to null which will remove the attribute
                // otherwise use newValue as is
                var valueToSet = (StringOrNone.NoneValue.Equals(newValue) ? null : newValue);
                var cmd        =
                    new UpdateDefaultableValueCommand <StringOrNone>(defaultableValueToUpdate, valueToSet);
                var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext();
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
            }
        }
Ejemplo n.º 2
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            if (_property == null)
            {
                throw new InvalidOperationException("InvokeInternal is called when _property is null.");
            }

            // if values are set to NoneValue then explictly remove the attribute,
            // if values are set to null then leave the attribute as is
            if (_theDefault != null)
            {
                _property.DefaultValue.Value = (_theDefault.Equals(StringOrNone.NoneValue) ? null : _theDefault);
            }
            if (_maxLength != null)
            {
                _property.MaxLength.Value = (_maxLength.Equals(DefaultableValueUIntOrNone.NoneValue) ? null : _maxLength);
            }
            if (_fixedLength != null)
            {
                _property.FixedLength.Value = (_fixedLength.Equals(BoolOrNone.NoneValue) ? null : _fixedLength);
            }
            if (_precision != null)
            {
                _property.Precision.Value = (_precision.Equals(DefaultableValueUIntOrNone.NoneValue) ? null : _precision);
            }
            if (_scale != null)
            {
                _property.Scale.Value = (_scale.Equals(DefaultableValueUIntOrNone.NoneValue) ? null : _scale);
            }
            if (_unicode != null)
            {
                _property.Unicode.Value = (_unicode.Equals(BoolOrNone.NoneValue) ? null : _unicode);
            }
            if (_collation != null)
            {
                _property.Collation.Value = (_collation.Equals(StringOrNone.NoneValue) ? null : _collation);
            }
            if (_concurrencyMode != null)
            {
                _property.ConcurrencyMode.Value = _concurrencyMode;
            }
        }