コード例 #1
0
        /// <summary>
        /// given instance with the destination instance using an specific key service
        /// </summary>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TDestination">The type of the destination.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="keyService">The key service.</param>
        /// <returns></returns>
        public TDestination TryToMerge <TSource, TDestination>(TSource source, TDestination destination, object keyService)
        {
            object src = source;
            object dst = destination;

            if (src == null || dst == null)
            {
                return(destination);
            }

            var serviceMerger = this.mergerResolver.FirstOrDefault(
                transformer => transformer.Match(keyService, typeof(TSource), typeof(TDestination))
                );

            if (serviceMerger == null)
            {
                return(destination);
            }

            ISourceMerger merger = serviceMerger.ServiceAs <ISourceMerger>();

            if (merger != null)
            {
                merger.Merge(source, destination);
            }

            return(destination);
        }
コード例 #2
0
        /// <summary>
        /// Tries to merge the given instance with the destination instance using an specific key service.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="keyService">The key service.</param>
        /// <returns></returns>
        public object TryToMerge(object source, object destination, object keyService)
        {
            if (source == null || destination == null)
            {
                return(destination);
            }

            var serviceMerger = this.mergerResolver.FirstOrDefault(
                transformer => transformer.Match(keyService, source.GetType(), destination.GetType()));

            if (serviceMerger == null)
            {
                return(destination);
            }

            ISourceMerger merger = serviceMerger.ServiceAs <ISourceMerger>();

            return(merger.Merge(source, destination));
        }