/// <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"); } m_maps.Add(map.Descriptor, map); }
/// <summary> /// <see cref="Kashef.Common.Utilities.TypeResolution.ITypeAdapter"/> /// </summary> /// <typeparam name="TSource"><see cref="Kashef.Common.Utilities.TypeResolution.ITypeAdapter"/></typeparam> /// <typeparam name="TTarget"><see cref="Kashef.Common.Utilities.TypeResolution.ITypeAdapter"/></typeparam> /// <param name="source"><see cref="Kashef.Common.Utilities.TypeResolution.ITypeAdapter"/></param> /// <returns><see cref="Kashef.Common.Utilities.TypeResolution.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 (m_maps.ContainsKey(descriptor)) { var spec = m_maps[descriptor] as TypeMapConfigurationBase <TSource, TTarget>; return(spec.Resolve(source)); } else { throw new InvalidOperationException(string.Format(Resources.Exception_NotMapFoundForTypeAdapter, typeof(TSource).FullName, typeof(TTarget).FullName)); } }