Exemple #1
0
 /// <summary>
 /// Register map into this register types map
 /// </summary>
 /// <typeparam name="TSource">The source type</typeparam>
 /// <typeparam name="TTarget">The type of the target.</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);
 }
Exemple #2
0
        /// <summary>
        ///     <see cref="iPow.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/>
        /// </summary>
        /// <typeparam name="TSource"><see cref="iPow.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/></typeparam>
        /// <typeparam name="TTarget"><see cref="iPow.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/></typeparam>
        /// <param name="source"><see cref="iPow.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/></param>
        /// <returns>
        ///     <see cref="iPow.Infrastructure.Crosscutting.Adapters.ITypeAdapter"/>
        /// </returns>
        public TTarget Adapt <TSource, TTarget>(TSource source)
            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>;
                return(spec.Resolve(source));
            }
            else
            {
                throw new InvalidOperationException(string.Format("Not mapped found for type {0} to type {1}",
                                                                  typeof(TSource).FullName,
                                                                  typeof(TTarget).FullName));
            }
        }