Example #1
0
        /// <summary>
        ///     Creates a member mapping info object to map the selected properties
        /// </summary>
        /// <param name="sourceProperty">
        ///     The source property
        /// </param>
        /// <param name="targetProperty">
        ///     The target property
        /// </param>
        /// <returns>
        ///     A new member mapping info object.
        /// </returns>
        protected virtual ReflectionPropertyMappingInfo <TSource, TTarget> CreateInfo(PropertyInfo sourceProperty,
                                                                                      PropertyInfo targetProperty)
        {
            var mappingInfo = new ReflectionPropertyMappingInfo <TSource, TTarget>(sourceProperty, targetProperty, false);

            return(mappingInfo);
        }
        public void MapTest()
        {
            var          a        = new TestClassA();
            var          c        = new TestClassC();
            PropertyInfo fromProp = typeof(TestClassA).GetProperty("Name");
            PropertyInfo toProp   = typeof(TestClassA).GetProperty("Name");
            var          mock     = new ConverterMock();
            bool         executed = false;

            mock.ConvertAction = (f, fp, t, tp, s) =>
            {
                Assert.AreEqual(c, f);
                Assert.AreEqual(fromProp, fp);
                Assert.AreEqual(a, t);
                Assert.AreEqual(toProp, tp);
                Assert.IsTrue(s);
                executed = true;
            };
            var target = new ReflectionPropertyMappingInfo <TestClassC, TestClassA>(
                fromProp, toProp, true, mock);

            target.Map(c, a);

            Assert.IsTrue(executed);
        }
Example #3
0
        /// <summary>
        ///     Gets the property mapping for two property types.
        /// </summary>
        /// <param name="firstProp">The first property.</param>
        /// <param name="secondProp">The second property.</param>
        /// <param name="direction">The direction of the mapping.</param>
        /// <returns>A property mapping object.</returns>
        private static ReflectionPropertyMappingInfo <TSource, TTarget> GetMapping(
            PropertyInfo firstProp,
            PropertyInfo secondProp,
            MappingDirections direction)
        {
            ReflectionPropertyMappingInfo <TSource, TTarget> mappingInfo;

            if (direction == MappingDirections.From)
            {
                mappingInfo = new ReflectionPropertyMappingInfo <TSource, TTarget>(
                    firstProp,
                    secondProp,
                    true);
            }
            else
            {
                mappingInfo = new ReflectionPropertyMappingInfo <TSource, TTarget>(
                    secondProp,
                    firstProp,
                    true);
            }

            return(mappingInfo);
        }
        public void MapTest()
        {
            var a = new TestClassA();
            var c = new TestClassC();
            PropertyInfo fromProp = typeof (TestClassA).GetProperty("Name");
            PropertyInfo toProp = typeof (TestClassA).GetProperty("Name");
            var mock = new ConverterMock();
            bool executed = false;

            mock.ConvertAction = (f, fp, t, tp, s) =>
            {
                Assert.AreEqual(c, f);
                Assert.AreEqual(fromProp, fp);
                Assert.AreEqual(a, t);
                Assert.AreEqual(toProp, tp);
                Assert.IsTrue(s);
                executed = true;
            };
            var target = new ReflectionPropertyMappingInfo<TestClassC, TestClassA>(
                fromProp, toProp, true, mock);
            target.Map(c, a);

            Assert.IsTrue(executed);
        }