private static Func <TSource, TTarget> CreateConverter(ObjectMapper container) { Func <TSource, TTarget> converter; if (container.Converters.Get <TSource, TTarget>() == null && (TryGetArrayConverter(container, out converter) || TryGetListConverter(container, out converter) || TryGetEnumerableConverter(container, out converter) || TryGetCollectionConverter(container, out converter))) { return(converter); } InstanceMapper <TSource, TTarget> mapper = InstanceMapper <TSource, TTarget> .GetInstance(container); return(mapper.Map); }
private static Action <TSource, TTarget> CreateMapper(ObjectMapper container) { Type sourceEnumerableType, targetEnumerableType; if (typeof(TSource).ImplementsGeneric(typeof(IEnumerable <>), out sourceEnumerableType) && typeof(TTarget).ImplementsGeneric(typeof(IEnumerable <>), out targetEnumerableType)) { Type sourceElementType = sourceEnumerableType.GetGenericArguments()[0]; Type targetElementType = targetEnumerableType.GetGenericArguments()[0]; return ((source, target) => container.FastInvoke(new[] { sourceElementType, targetElementType }, "Map", source, target)); } InstanceMapper <TSource, TTarget> mapper = InstanceMapper <TSource, TTarget> .GetInstance(container); return(mapper.Map); }
/// <summary> /// Returns a mapper instance for specified types. /// </summary> /// <typeparam name="TSource">The type of source object.</typeparam> /// <typeparam name="TTarget">The type of target object.</typeparam> /// <returns>A mapper instance for specified types.</returns> public IInstanceMapper <TSource, TTarget> GetMapper <TSource, TTarget>() { return(InstanceMapper <TSource, TTarget> .GetInstance(this)); }