Пример #1
0
        /// <summary>
        /// Configures the builder to set a property with the informed value.
        /// </summary>
        public FluentBuilder <T> With <TProperty>(Expression <Func <T, TProperty> > expression, TProperty newValue)
        {
            var propertyName = GetMemberQuery.GetMemberNameFor(expression);

            _commands[propertyName] = new SetPropertyCommand(_newObject, propertyName, newValue);
            return(this);
        }
        /// <summary>
        /// Modifies the new value with modifier.
        /// If the new value is not equal to the current value:
        /// 1. It creates a new undo/redo SetPropertyCommand and registers it in undoRedoManager.
        /// 2. Each time the property is changed by the SetPropertyCommand, NotifyPropertyChanged will be executed.
        /// 3. If notifyObjectChanged is set to true, each time the property is changed by the SetPropertyCommand, NotifyObjectChanged will be executed.
        /// </summary>
        protected void SetPropertyUndoRedo <T> (Action <T> setter, Func <T> getter, T newValue,
                                                bool notifyObjectChanged               = false,
                                                Func <T, T> modifier                   = null,
                                                [CallerFilePath] string pathName       = "",
                                                [CallerMemberName] string propertyName = "")
        {
            Assert.ArgumentNotNull(setter, nameof(setter));
            Assert.ArgumentNotNull(getter, nameof(getter));

            if (modifier != null)
            {
                newValue = modifier(newValue);
            }

            if (!EqualityComparer <T> .Default.Equals(getter(), newValue))
            {
                Action callback = () => NotifyPropertyChanged(propertyName);

                if (notifyObjectChanged)
                {
                    callback += () => NotifyChanged();
                }

                var command = new SetPropertyCommand <T> (new Ref <T> (setter, getter), newValue, callback, pathName, propertyName);
                undoRedoManager.Do(command as ICommand);
            }
        }
        public void Should_set_a_writable_property_when_value_inherits_from_property_type()
        {
            const string propertyName = "AbstractProperty";
            var          newValue     = new ConcreteSampleType();
            var          command      = new SetPropertyCommand(_object, propertyName, newValue);

            command.Execute();

            Assert.AreEqual(newValue, _object.AbstractProperty);
        }
        public void Should_set_a_writable_property()
        {
            const string propertyName = "WritableProperty";
            const int    newValue     = 10;
            var          command      = new SetPropertyCommand(_object, propertyName, newValue);

            command.Execute();

            Assert.AreEqual(newValue, _object.WritableProperty);
        }
        public void Intercept(IInvocation invocation)
        {
            if (!(invocation.InvocationTarget is Device))
            {
                invocation.Proceed();
                return;
            }

            if (!invocation.Method.Name.StartsWith("set_"))
            {
                invocation.Proceed();
                return;
            }

            var propertyName = invocation.Method.Name.Substring(4);
            var getterName   = "get_" + propertyName;

            var getter = invocation.TargetType.GetMethod(getterName);

            if (getter == null)
            {
                invocation.Proceed();
                return;
            }

            if (!getter.IsPublic)
            {
                invocation.Proceed();
                return;
            }

            invocation.Proceed();

            var device = (Device)(invocation.InvocationTarget);

            var command = new SetPropertyCommand(device.Id, Serializer.Resolver.GetResolvedPropertyName(propertyName),
                                                 invocation.GetArgumentValue(0));

            CommandBus.Instance.Publish(command).ContinueWith((obj) => { });
        }
Пример #6
0
        public IActionResult SetPropertyName([FromBody] SetPropertyCommand updatpropertyname)
        {
            Task <CommandResult> result = mediator.Send(updatpropertyname);

            return(Ok());
        }