protected internal int CacheCompiledInfos(IDictionary <int, MappingCompiledInfo> mappingCompiledInfos) { Lock.EnterWriteLock(); try { return(CompiledCache.CacheAll(mappingCompiledInfos)); } finally { Lock.ExitWriteLock(); } }
/// <summary> /// Clears all mappings and compiled caches. /// </summary> public void Clear() { Lock.EnterWriteLock(); try { MappingRows.Clear(); CompiledCache.Clear(); } finally { Lock.ExitWriteLock(); } }
public bool CacheCompiledInfo(Type destinationType, Type sourceType, MappingCompiledInfo mappingCompiledInfo) { var hash = Mapping.ComputeHash(destinationType, sourceType); Lock.EnterWriteLock(); try { return(CompiledCache.Cache(hash, mappingCompiledInfo)); } finally { Lock.ExitWriteLock(); } }
/// <summary> /// Adds a mapping to <see cref="MapperContext"/>. /// </summary> /// <param name="item"></param> public void Add(Mapping item) { var hash = Mapping.ComputeHash(item); Lock.EnterWriteLock(); try { MappingRows.Add(hash, item); CompiledCache.Miss(hash); } finally { Lock.ExitWriteLock(); } }
/// <summary> /// Returns the <see cref="MappingCompiledInfo"/> using given destinationType and sourceType. /// </summary> /// <param name="destinationType"></param> /// <param name="sourceType"></param> /// <param name="mappingCompiledInfo"></param> /// <returns>A value indicating that value is found or not.</returns> public bool TryGetCompiledInfo(Type destinationType, Type sourceType, out MappingCompiledInfo mappingCompiledInfo) { var hash = Mapping.ComputeHash(destinationType, sourceType); Lock.EnterReadLock(); try { return(CompiledCache.TryGetValue(hash, out mappingCompiledInfo)); } finally { Lock.ExitReadLock(); } }
/// <summary> /// Removes a mapping (and it's compiled cache) from <see cref="MapperContext"/>. /// </summary> /// <param name="destinationType"></param> /// <param name="sourceType"></param> /// <returns></returns> public bool Remove(Type destinationType, Type sourceType) { var hash = Mapping.ComputeHash(destinationType, sourceType); Lock.EnterWriteLock(); try { var result = MappingRows.Remove(hash); CompiledCache.Miss(hash); return(result); } finally { Lock.ExitWriteLock(); } }
/// <summary> /// Removes a mapping (and it's compiled cache) from <see cref="MapperContext"/>. /// </summary> /// <param name="item"></param> /// <returns></returns> public bool Remove(Mapping item) { var hash = Mapping.ComputeHash(item); Lock.EnterWriteLock(); try { var result = MappingRows.Remove(hash); CompiledCache.Miss(hash); return(result); } finally { Lock.ExitWriteLock(); } }
public bool TryGetMappingAndCompiledInfo(Type destinationType, Type sourceType, out Mapping mapping, out MappingCompiledInfo mappingCompiledInfo) { var hash = Mapping.ComputeHash(destinationType, sourceType); Lock.EnterReadLock(); try { var result = MappingRows.TryGetValue(hash, out mapping); CompiledCache.TryGetValue(hash, out mappingCompiledInfo); return(result); } finally { Lock.ExitReadLock(); } }
/// <summary> /// Adds a range of mappings to <see cref="MapperContext"/>. /// </summary> /// <param name="items"></param> public void AddRange(IEnumerable <Mapping> items) { var hashes = new List <int>(); Lock.EnterWriteLock(); try { foreach (var item in items) { var hash = Mapping.ComputeHash(item); MappingRows.Add(hash, item); hashes.Add(hash); } CompiledCache.MissAll(hashes); } finally { Lock.ExitWriteLock(); } }
/// <summary> /// Gets all mappings without equivalent compiled info. (Those which needing compilation). /// </summary> protected internal IDictionary <int, Mapping> GetMappingsWithoutCompiledInfo() { var result = new Dictionary <int, Mapping>(); Lock.EnterReadLock(); try { foreach (var row in MappingRows) { if (!CompiledCache.Exists(row.Key)) { result.Add(row.Key, row.Value); } } return(result); } finally { Lock.ExitReadLock(); } }