Пример #1
0
        public object Adapt(object source, Type sourceType, Type destinationType)
        {
            var fn     = _config.GetMapFunction(sourceType, destinationType);
            var result = fn.DynamicInvoke(source);

            MapContext.Clear();
            return(result);
        }
Пример #2
0
 /// <summary>
 /// Adapte the source object to the destination type.
 /// </summary>
 /// <typeparam name="TSource">Source type.</typeparam>
 /// <typeparam name="TDestination">Destination type.</typeparam>
 /// <param name="source">Source object to adapt.</param>
 /// <returns>Adapted destination type.</returns>
 public static TDestination Adapt <TSource, TDestination>(TSource source)
 {
     try
     {
         return(TypeAdapter <TSource, TDestination> .Map(source));
     }
     finally
     {
         MapContext.Clear();
     }
 }
Пример #3
0
        /// <summary>
        /// Adapte the source object to the destination type.
        /// </summary>
        /// <typeparam name="TSource">Source type.</typeparam>
        /// <typeparam name="TDestination">Destination type.</typeparam>
        /// <param name="source">Source object to adapt.</param>
        /// <param name="config">Configuration</param>
        /// <returns>Adapted destination type.</returns>
        public static TDestination Adapt <TSource, TDestination>(TSource source, TypeAdapterConfig config)
        {
            var fn = config.GetMapFunction <TSource, TDestination>();

            try
            {
                return(fn(source));
            }
            finally
            {
                MapContext.Clear();
            }
        }
Пример #4
0
        public object Adapt(object source, object destination, Type sourceType, Type destinationType)
        {
            dynamic fn = _config.GetMapFunction(sourceType, destinationType);

            try
            {
                return(fn((dynamic)source));
            }
            finally
            {
                MapContext.Clear();
            }
        }
Пример #5
0
        public TDestination Adapt <TSource, TDestination>(TSource source, TDestination destination)
        {
            var fn = _config.GetMapToTargetFunction <TSource, TDestination>();

            try
            {
                return(fn(source, destination));
            }
            finally
            {
                MapContext.Clear();
            }
        }
Пример #6
0
        public TDestination Adapt <TDestination>(object source)
        {
            dynamic fn = _config.GetMapFunction(source.GetType(), typeof(TDestination));

            try
            {
                return(fn((dynamic)source));
            }
            finally
            {
                MapContext.Clear();
            }
        }
Пример #7
0
        /// <summary>
        /// Adapte the source object to the existing destination object.
        /// </summary>
        /// <typeparam name="TSource">Source type.</typeparam>
        /// <typeparam name="TDestination">Destination type.</typeparam>
        /// <param name="source">Source object to adapt.</param>
        /// <param name="destination">The destination object to populate.</param>
        /// <param name="config">Configuration</param>
        /// <returns>Adapted destination type.</returns>
        public static TDestination Adapt <TSource, TDestination>(TSource source, TDestination destination, TypeAdapterConfig config = null)
        {
            config = config ?? TypeAdapterConfig.GlobalSettings;
            var fn = config.GetMapToTargetFunction <TSource, TDestination>();

            try
            {
                return(fn(source, destination));
            }
            finally
            {
                MapContext.Clear();
            }
        }
Пример #8
0
        /// <summary>
        /// Adapte the source object to the destination type.
        /// </summary>
        /// <typeparam name="TDestination">Destination type.</typeparam>
        /// <param name="source">Source object to adapt.</param>
        /// <param name="config">Configuration</param>
        /// <returns>Adapted destination type.</returns>
        public static TDestination Adapt <TDestination>(object source, TypeAdapterConfig config = null)
        {
            config = config ?? TypeAdapterConfig.GlobalSettings;
            dynamic fn = config.GetMapFunction(source.GetType(), typeof(TDestination));

            try
            {
                return(fn((dynamic)source));
            }
            finally
            {
                MapContext.Clear();
            }
        }
Пример #9
0
        /// <summary>
        /// Adapte the source object to an existing destination object.
        /// </summary>
        /// <param name="source">Source object to adapt.</param>
        /// <param name="destination">Destination object to populate.</param>
        /// <param name="sourceType">The type of the source object.</param>
        /// <param name="destinationType">The type of the destination object.</param>
        /// <param name="config">Configuration</param>
        /// <returns>Adapted destination type.</returns>
        public static object Adapt(object source, object destination, Type sourceType, Type destinationType, TypeAdapterConfig config = null)
        {
            config = config ?? TypeAdapterConfig.GlobalSettings;
            dynamic fn = config.GetMapToTargetFunction(sourceType, destinationType);

            try
            {
                return(fn((dynamic)source, (dynamic)destination));
            }
            finally
            {
                MapContext.Clear();
            }
        }