コード例 #1
0
ファイル: Faller.cs プロジェクト: Skycweb/blqw-Faller
 private void Parse(NewArrayExpression expr)
 {
     var exps = expr.Expressions;
     var length = expr.Expressions.Count;
     var arr = Array.CreateInstance(expr.Type.GetElementType(), length);
     for (int i = 0; i < length; i++)
     {
         Parse(exps[i]);
         if (_state.DustType != DustType.Sql)
         {
             arr.SetValue(_state.Object, i);
         }
         else
         {
             var arr1 = new ISawDust[length];
             var dust = GetSawDust();
             if (i > 0)
             {
                 _state.Object = arr.GetValue(0);
                 arr1[0] = new SawDust(this, _state.DustType, arr.GetValue(0));
                 for (int j = 1; j < i; j++)
                 {
                     arr1[j] = new SawDust(this, _state.DustType, arr.GetValue(j));
                 }
             }
             for (; i < length; i++)
             {
                 Parse(exps[i]);
                 arr1[i] = GetSawDust();
             }
             _state.Array = arr1;
             return;
         }
     }
     _state.Array = arr;
 }
コード例 #2
0
ファイル: Faller.cs プロジェクト: Skycweb/blqw-Faller
        /// <summary> 解析方法,如果全部是常量,则直接执行
        /// </summary>
        /// <param name="expr">方法表达式</param>
        /// <param name="target">方法的调用实例</param>
        /// <param name="args">方法参数</param>
        /// <returns></returns>
        private bool TryInvoke(MethodCallExpression expr, out ISawDust target, out ISawDust[] args)
        {
            ISubExpression subexpr = null;
            //判断方法调用实例,如果是null为静态方法,反之为实例方法
            if (expr.Object == null)
            {
                target = new SawDust(this, DustType.Object, null);
            }
            else
            {
                Parse(expr.Object);
                if (_state.DustType == DustType.SubExpression) subexpr = _state.SubExpression;
                target = GetSawDust();
            }

            var exprArgs = expr.Arguments;
            var length = exprArgs.Count;
            args = new ISawDust[length];
            var call = target.Type != DustType.Sql;
            for (int i = 0; i < length; i++)
            {
                Parse(exprArgs[i]);
                if (_state.DustType == DustType.Sql)
                {
                    if (call) call = false;
                    args[i] = new SawDust(this, DustType.Sql, _state.Sql);
                }
                else if (_state.DustType == DustType.Array && _state.Array is ISawDust[])
                {
                    if (call) call = false;
                    args[i] = new SawDust(this, DustType.Array, _state.Array);
                }
                else
                {
                    args[i] = new SawDust(this, _state.DustType, _state.Object);
                }
            }

            if (call)
            {
                var method = expr.Method;
                if (subexpr != null && !TypesHelper.IsChild(typeof(ISubExpression), method.ReturnType))
                {
                    _state.Sql = subexpr.GetSqlString(args);
                }
                else
                {
                    _state.Object = method.Invoke(target.Value, args.Select(it => it.Value).ToArray());
                }
                return true;
            }
            else
            {
                return false;
            }
        }