コード例 #1
0
ファイル: Reflect.cs プロジェクト: redchew-fork/Fasterflect
        /// <summary>
        /// Creates a delegate that can map values from fields and properties on the source object to fields and properties on the target object.
        /// </summary>
        /// <param name="sourceType">The type of the source object.</param>
        /// <param name="targetType">The type of the target object.</param>
        /// <param name="bindingFlags">The <see cref="BindingFlags"/> or <see cref="FasterflectFlags"/> to filter the members.</param>
        /// <param name="sourceNames">The member names (Fields, Properties or both) to include on the source.</param>
        /// <param name="targetNames">The member names (Fields, Properties or both) to include on the target.</param>
        /// <returns>An <see cref="ObjectMapper"/> which sets the target using the matching source members.</returns>
        internal static ObjectMapper Mapper(Type sourceType, Type targetType, FasterflectFlags bindingFlags, string[] sourceNames, string[] targetNames)
        {
            MapCallInfo  info  = new MapCallInfo(sourceType, targetType, bindingFlags, sourceNames, targetNames);
            ObjectMapper value = Mappers.Get(info);

            if (value != null)
            {
                return(value);
            }
            value = (ObjectMapper) new MapEmitter(info).GetDelegate();
            Mappers.Insert(info, value);
            return(value);
        }
コード例 #2
0
        public void TestMapCallInfoHashCodeUniqueness()
        {
            MapCallInfo map1 = GetMapCallInfo(typeof(A1), typeof(A2), "P1");
            MapCallInfo map2 = GetMapCallInfo(typeof(A2), typeof(A1), "P1");

            Assert.AreNotEqual(map1.GetHashCode(), map2.GetHashCode());
            map1 = GetMapCallInfo(typeof(B1), typeof(B2), "P1");
            map2 = GetMapCallInfo(typeof(B2), typeof(B1), "P1");
            Assert.AreNotEqual(map1.GetHashCode(), map2.GetHashCode());
            map1 = GetMapCallInfo(typeof(B1), typeof(B2), "P2");
            map2 = GetMapCallInfo(typeof(B2), typeof(B1), "P2");
            Assert.AreNotEqual(map1.GetHashCode(), map2.GetHashCode());
            map1 = GetMapCallInfo(typeof(B1), typeof(B2), "P1", "P2");
            map2 = GetMapCallInfo(typeof(B2), typeof(B1), "P1", "P2");
            Assert.AreNotEqual(map1.GetHashCode(), map2.GetHashCode());
        }