Esempio n. 1
0
        internal static IntPtr SelectScalar(ForeachFunc foreachFunc, string filterExpression,
                                            CloneFunc cloneFunc)
        {
            using (var filter = QueryArguments.CreateNativeHandle(filterExpression))
            {
                IntPtr handle = IntPtr.Zero;

                foreachFunc(filter, (itemHandle, _) =>
                {
                    cloneFunc(out handle, itemHandle);
                    return(false);
                }).ThrowIfError("Failed to execute query");

                return(handle);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// IL动态代码(Emit),复制(实体及列表)
 /// 并行处理列表复制
 /// </summary>
 internal static object CloneObject(object obj, bool depth)
 {
     if (obj is IList list)
     {
         var      type = list.GenericType();
         Delegate action;
         lock (SyncRoot)
         {
             if (!CloneAction.TryGetValue(type.FullName + "." + depth, out action))
             {
                 action = CloneBuilder.CloneAction(type, depth);
                 CloneAction.Add(type.FullName + "." + depth, action);
             }
         }
         var iList = type.GenericList();
         for (int i = 0; i < list.Count; i++)
         {
             iList.Add(Activator.CreateInstance(type));
         }
         Parallel.For(0, list.Count, (i) =>
         {
             ((Action <object, object>)action)(list[i], iList[i]);
         });
         return(iList);
     }
     else if (obj != null)
     {
         var      type = obj.GetType();
         Delegate func;
         lock (SyncRoot)
         {
             if (!CloneFunc.TryGetValue(type.FullName + "." + depth, out func))
             {
                 func = CloneBuilder.CloneFunc(type, depth);
                 CloneFunc.Add(type.FullName + "." + depth, func);
             }
         }
         return(((Func <object, object>)func)(obj));
     }
     return(null);
 }