Ejemplo n.º 1
0
        /// <summary>
        ///     Retrieve the IMapper implementation to be used for a specified POCO type.
        /// </summary>
        /// <param name="entityType">The entity type to get the mapper for.</param>
        /// <param name="defaultMapper">The default mapper to use when non is registered for the type.</param>
        /// <returns>The mapper for the given type.</returns>
        public static StandardMapper GetMapper(Type entityType, StandardMapper defaultMapper)
        {
            _lock.EnterReadLock();
            try
            {
                StandardMapper val;
                if (_mappers.TryGetValue(entityType, out val))
                {
                    return(val);
                }
                if (_mappers.TryGetValue(entityType.Assembly, out val))
                {
                    return(val);
                }
                if (defaultMapper == null)
                {
                    return(new StandardMapper());
                }


                return(defaultMapper);
            }
            finally
            {
                _lock.ExitReadLock();
            }
        }
Ejemplo n.º 2
0
 private static void RegisterInternal(object typeOrAssembly, StandardMapper mapper)
 {
     _lock.EnterWriteLock();
     try
     {
         _mappers.Add(typeOrAssembly, mapper);
     }
     finally
     {
         _lock.ExitWriteLock();
         FlushCaches();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Revoke an instance of a mapper
 /// </summary>
 /// <param name="mapper">The IMapper to be revkoed</param>
 public static void Revoke(StandardMapper mapper)
 {
     _lock.EnterWriteLock();
     try
     {
         foreach (var i in _mappers.Where(kvp => kvp.Value == mapper).ToList())
         {
             _mappers.Remove(i.Key);
         }
     }
     finally
     {
         _lock.ExitWriteLock();
         FlushCaches();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Registers a mapper for a single POCO type
 /// </summary>
 /// <param name="type">The type to be managed by this mapper</param>
 /// <param name="mapper">The IMapper implementation</param>
 public static void Register(Type type, StandardMapper mapper)
 {
     RegisterInternal(type, mapper);
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Registers a mapper for all types in a specific assembly
 /// </summary>
 /// <param name="assembly">The assembly whose types are to be managed by this mapper</param>
 /// <param name="mapper">The IMapper implementation</param>
 public static void Register(Assembly assembly, StandardMapper mapper)
 {
     RegisterInternal(assembly, mapper);
 }