/// <summary> /// <see cref="ITypeAdapter"/> /// </summary> /// <typeparam name="TSource"><see cref="TomorrowSoft.Framework.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/></typeparam> /// <typeparam name="TTarget"><see cref="TomorrowSoft.Framework.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/></typeparam> /// <param name="source"><see cref="TomorrowSoft.Framework.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/></param> /// <returns><see cref="TomorrowSoft.Framework.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/></returns> public TTarget Adapt <TSource, TTarget>(TSource source, TTarget target) where TSource : class where TTarget : class, new() { if (source == (TSource)null) { throw new ArgumentNullException("source"); } var descriptor = TypeMapConfigurationBase <TSource, TTarget> .GetDescriptor(); if (_maps.ContainsKey(descriptor)) { var spec = _maps[descriptor] as TypeMapConfigurationBase <TSource, TTarget>; if (target == null) { return(spec.Resolve(source)); } else { return(spec.Resolve(source, target)); } } else { throw new InvalidOperationException(string.Format(Messages.exception_NotMapFoundForTypeAdapter, typeof(TSource).FullName, typeof(TTarget).FullName)); } }
/// <summary> /// Register map into this register types map /// </summary> /// <typeparam name="TSource">The source type</typeparam> /// <typeparam name="TTarget">The target type</typeparam> /// <param name="map">The map to register</param> public void RegisterMap <TSource, TTarget>(TypeMapConfigurationBase <TSource, TTarget> map) where TSource : class where TTarget : class, new() { if (map == (TypeMapConfigurationBase <TSource, TTarget>)null) { throw new ArgumentNullException("map"); } _maps.Add(map.Descriptor, map); }