Esempio n. 1
0
        /// <summary>
        /// Add simple or complex item that maps source member to destination member.
        /// </summary>
        private Map AddItem <TSourceMember, TDestinationMember>(TSourceMember source, TDestinationMember destination, bool complex)
            where TSourceMember : MemberInfo
            where TDestinationMember : MemberInfo
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            var sourceItem      = new MapItem.Item(source, true);
            var destinationItem = new MapItem.Item(destination, false);

            MapItem mapping = new MapItem(sourceItem, destinationItem, this);

            this.items.Add(mapping);

            if (complex)
            {
                Map subMap = MapResolver.Resolve(sourceItem.Type, destinationItem.Type);

                mapping.IsComplex = true;

                subMaps.Add(mapping.Key, subMap);
            }

            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Maps source object to destination object.
        /// </summary>
        private static void Map(object source, object destination, Type sourceType, Type destinationType)
        {
            //// get new or previously resolved map
            Map map = MapResolver.Resolve(sourceType, destinationType);

            //// map source to destination
            Map(map, source, destination, sourceType, destinationType);
        }
Esempio n. 3
0
        /// <summary>
        /// Add simple or complex item that maps source member to destination member.
        /// </summary>
        private Map AddItem(string sourceMemberName, Type sourceType, string destinationMemberName, Type destinationType, bool complex)
        {
            if (String.IsNullOrWhiteSpace(sourceMemberName))
            {
                throw new ArgumentNullException("sourceMemberName");
            }

            if (String.IsNullOrWhiteSpace(destinationMemberName))
            {
                throw new ArgumentNullException("destinationMemberName");
            }

            if (sourceType == null)
            {
                throw new ArgumentNullException("sourceType");
            }

            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            MemberInfo sm = sourceType.GetMember(sourceMemberName).FirstOrDefault();
            MemberInfo dm = destinationType.GetMember(destinationMemberName).FirstOrDefault();

            MapItem.Item sourceItem      = null;
            MapItem.Item destinationItem = null;
            MapItem      mapping         = null;

            if (sm != null && dm != null)
            {
                sourceItem      = new MapItem.Item(sm, true);
                destinationItem = new MapItem.Item(dm, false);
                mapping         = new MapItem(sourceItem, destinationItem, this);

                this.items.Add(mapping);
            }

            if (mapping != null)
            {
                if (complex)
                {
                    Map subMap = MapResolver.Resolve(sourceItem.Type, destinationItem.Type);

                    mapping.IsComplex = true;

                    subMaps.Add(mapping.Key, subMap);
                }
            }

            return(this);
        }
Esempio n. 4
0
 /// <summary>
 /// Removes map between source and destination type.
 /// </summary>
 /// <returns>true if map was removed; false otherwise.</returns>
 public static bool RemoveMap(Type sourceType, Type destinationType)
 {
     return(MapResolver.Remove(sourceType, destinationType));
 }
Esempio n. 5
0
 /// <summary>
 /// Removes map between source and destination type.
 /// </summary>
 /// <returns>true if map was removed; false otherwise.</returns>
 public static bool RemoveMap <TSource, TDestination>() where TDestination : new()
 {
     return(MapResolver.Remove <TSource, TDestination>());
 }
Esempio n. 6
0
 /// <summary>
 /// Resolves <see cref="IMap"/> between source and destination type.
 /// </summary>
 /// <returns>A resolved map.</returns>
 public static IMap Resolve(Type sourceType, Type destinationType, MapResolveOptions options = MapResolveOptions.None)
 {
     return(MapResolver.Resolve(sourceType, destinationType, options));
 }
Esempio n. 7
0
 /// <summary>
 /// Resolves <see cref="IMap"/> between source and destination type.
 /// </summary>
 /// <returns>A resolved map.</returns>
 public static IMap Resolve <TSource, TDestination>(MapResolveOptions options = MapResolveOptions.None) where TDestination : new()
 {
     return(MapResolver.Resolve <TSource, TDestination>(options));
 }