示例#1
0
文件: Cloner.cs 项目: deipax/Deipax
        public static T Get(T source, CopyContext context)
        {
            if (source == null)
            {
                return(source);
            }
            var runtimeType = source.GetType();

            CloneDel <T> del = runtimeType == _type
                ? _del
                : _cache.GetOrAdd(runtimeType, _create);

            return(del(source, context));
        }
示例#2
0
 public T Find(Predicate <T> selector, CloneDel copyMaker, int timeout)
 {
     if (!locker.TryEnterReadLock(timeout))
     {
         return(default(T));
     }
     try
     {
         var obj = list.FirstOrDefault(l => selector(l));
         if (null == obj || obj.Equals(default(T)))
         {
             return(default(T));
         }
         return(copyMaker(obj));
     }
     catch
     {
         return(default(T));
     }
     finally
     {
         locker.ExitReadLock();
     }
 }