Simple, expression-based implementation of IBinding that binds source to target one-to-one.
Наследование: Spring.DataBinding.AbstractSimpleBinding
Пример #1
0
        /// <summary>
        /// Adds the <see cref="SimpleExpressionBinding"/> binding.
        /// </summary>
        /// <param name="sourceExpression">
        /// The source expression.
        /// </param>
        /// <param name="targetExpression">
        /// The target expression.
        /// </param>
        /// <param name="direction">
        /// Binding direction.
        /// </param>
        /// <param name="formatter">
        /// <see cref="IFormatter"/> to use for value formatting and parsing.
        /// </param>
        /// <returns>
        /// Added <see cref="SimpleExpressionBinding"/> instance.
        /// </returns>
        public virtual IBinding AddBinding(string sourceExpression, string targetExpression,
                                           BindingDirection direction, IFormatter formatter)
        {
            SimpleExpressionBinding binding = new SimpleExpressionBinding(sourceExpression, targetExpression);

            binding.Direction = direction;
            binding.Formatter = formatter;
            bindings.Add(binding);

            return(binding);
        }
Пример #2
0
        public void HandledTypeConversionExceptionTargetToSource()
        {
            BaseBindingManager dbm    = new BaseBindingManager();
            IValidationErrors  errors = new ValidationErrors();
            Inventor           st     = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            st.Inventions = new string[] { "Invention One", "Invention Two" };

            SimpleExpressionBinding binding = new SimpleExpressionBinding("pob", "DOB");

            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindTargetToSource(st, st, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindSourceToTarget(st, st, errors);
            Assert.AreEqual(new DateTime(1856, 7, 9), st.DOB);
        }
Пример #3
0
        public void HandledTypeConversionExceptionSourceToTarget()
        {
            BaseBindingManager dbm    = new BaseBindingManager();
            IValidationErrors  errors = new ValidationErrors();
            Hashtable          source = new Hashtable();

            source["boolValue"] = false;
            Inventor target = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            SimpleExpressionBinding binding = new SimpleExpressionBinding("['boolValue']", "DOB");

            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindSourceToTarget(source, target, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindTargetToSource(source, target, errors);
            Assert.AreEqual(false, source["boolValue"]);
        }
        public void HandledTypeConversionExceptionTargetToSource()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            IValidationErrors errors = new ValidationErrors();
            Inventor st = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            st.Inventions = new string[] {"Invention One", "Invention Two"};

            SimpleExpressionBinding binding = new SimpleExpressionBinding("pob", "DOB");
            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindTargetToSource(st, st, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindSourceToTarget(st, st, errors);
            Assert.AreEqual(new DateTime(1856, 7, 9), st.DOB);
        }
        public void HandledTypeConversionExceptionSourceToTarget()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            IValidationErrors errors = new ValidationErrors();
            Hashtable source = new Hashtable();
            source["boolValue"] = false;
            Inventor target = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            SimpleExpressionBinding binding = new SimpleExpressionBinding("['boolValue']", "DOB");
            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindSourceToTarget(source, target, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindTargetToSource(source, target, errors);
            Assert.AreEqual(false, source["boolValue"]);
        }
        /// <summary>
        /// Adds the <see cref="SimpleExpressionBinding"/> binding.
        /// </summary>
        /// <param name="sourceExpression">
        /// The source expression.
        /// </param>
        /// <param name="targetExpression">
        /// The target expression.
        /// </param>
        /// <param name="direction">
        /// Binding direction.
        /// </param>
        /// <param name="formatter">
        /// <see cref="IFormatter"/> to use for value formatting and parsing.
        /// </param>
        /// <returns>
        /// Added <see cref="SimpleExpressionBinding"/> instance.
        /// </returns>
        public virtual IBinding AddBinding(string sourceExpression, string targetExpression,
                                           BindingDirection direction, IFormatter formatter)
        {
            SimpleExpressionBinding binding = new SimpleExpressionBinding(sourceExpression, targetExpression);
            binding.Direction = direction;
            binding.Formatter = formatter;
            bindings.Add(binding);

            return binding;
        }