示例#1
0
        /// <summary>
        /// Returns the result of the operator applied to the operands.
        /// </summary>
        /// <param name="left">The left operand.</param>
        /// <param name="right">The right operand..</param>
        /// <param name="context">
        /// The <see cref="T:Dt.CalcEngine.CalcEvaluatorContext" /> associate with the operator evaluation.
        /// </param>
        /// <returns>
        /// Result of the operator applied to the operand.
        /// </returns>
        public override object Evaluate(object left, object right, CalcEvaluatorContext context)
        {
            CalcReference reference  = left as CalcReference;
            CalcReference reference2 = right as CalcReference;

            if (((reference == null) || (reference2 == null)) || (((reference.RangeCount != 1) || (reference2.RangeCount != 1)) || !reference.GetSource().Equals(reference2.GetSource())))
            {
                return(CalcErrors.Value);
            }
            CalcReference source = reference.GetSource();

            if ((source == null) || !source.Equals(reference2.GetSource()))
            {
                return(CalcErrors.Value);
            }
            int row         = reference.GetRow(0);
            int column      = reference.GetColumn(0);
            int num3        = reference2.GetRow(0);
            int num4        = reference2.GetColumn(0);
            int num5        = Math.Max(row, num3);
            int num6        = Math.Max(column, num4);
            int rowCount    = Math.Min((int)(row + reference.GetRowCount(0)), (int)(num3 + reference2.GetRowCount(0))) - num5;
            int columnCount = Math.Min((int)(column + reference.GetColumnCount(0)), (int)(num4 + reference2.GetColumnCount(0))) - num6;

            if ((rowCount >= 1) && (columnCount >= 1))
            {
                return(new ConcreteReference(source, num5, num6, rowCount, columnCount));
            }
            return(CalcErrors.Null);
        }
示例#2
0
        /// <summary>
        /// Returns the result of the operator applied to the operands.
        /// </summary>
        /// <param name="left">The left operand.</param>
        /// <param name="right">The right operand..</param>
        /// <param name="context">
        /// The <see cref="T:Dt.CalcEngine.CalcEvaluatorContext" /> associate with the operator evaluation.
        /// </param>
        /// <returns>
        /// Result of the operator applied to the operand.
        /// </returns>
        public override object Evaluate(object left, object right, CalcEvaluatorContext context)
        {
            CalcReference reference  = left as CalcReference;
            CalcReference reference2 = right as CalcReference;

            if ((reference == null) || (reference2 == null))
            {
                return(CalcErrors.Value);
            }
            int rangeCount = reference.RangeCount;
            int num2       = reference2.RangeCount;

            ConcreteReference.Range[] areas = new ConcreteReference.Range[rangeCount + num2];
            for (int i = 0; i < rangeCount; i++)
            {
                int row         = reference.GetRow(i);
                int column      = reference.GetColumn(i);
                int rowCount    = reference.GetRowCount(i);
                int columnCount = reference.GetColumnCount(i);
                areas[i] = new ConcreteReference.Range(row, column, rowCount, columnCount);
            }
            for (int j = 0; j < num2; j++)
            {
                int num9  = reference2.GetRow(j);
                int num10 = reference2.GetColumn(j);
                int num11 = reference2.GetRowCount(j);
                int num12 = reference2.GetColumnCount(j);
                areas[rangeCount + j] = new ConcreteReference.Range(num9, num10, num11, num12);
            }
            return(new ConcreteReference(reference.GetSource(), areas));
        }
示例#3
0
        internal override object EvaluteSingleValue(object operand, CalcEvaluatorContext context)
        {
            double num;

            if (CalcConvert.TryToDouble(operand, out num, true))
            {
                return((double)(num / 100.0));
            }
            return(CalcErrors.Value);
        }
示例#4
0
        internal override object EvaluteSingleValue(object operand, CalcEvaluatorContext context)
        {
            double num;

            if (operand is TimeSpan)
            {
                return((TimeSpan)operand);
            }
            if (CalcConvert.TryToDouble(operand, out num, true))
            {
                return((double)num);
            }
            if (operand is string)
            {
                return(operand);
            }
            return(CalcErrors.Value);
        }
示例#5
0
        private static object EvaluateImp(object[] args, object context)
        {
            CalcEvaluatorContext objA = context as CalcEvaluatorContext;

            if (object.ReferenceEquals(objA, null))
            {
                return(CalcErrors.Value);
            }
            bool          arrayFormulaMode = objA.ArrayFormulaMode;
            CalcReference reference        = CalcHelper.ArgumentExists(args, 0) ? (args[0] as CalcReference) : (objA.GetReference(new CalcRangeIdentity(objA.Row, objA.Column, objA.RowCount, objA.ColumnCount)) as CalcReference);

            if ((reference == null) || (reference.RangeCount != 1))
            {
                return(CalcErrors.Value);
            }
            if (arrayFormulaMode)
            {
                return(new CellInfoReference(reference.GetSource(), reference.GetRow(0), reference.GetColumn(0), reference.GetRowCount(0), reference.GetColumnCount(0), CellInfoReference.CellInfoType.Column));
            }
            return((int)(reference.GetColumn(0) + 1));
        }
示例#6
0
        internal override object EvaluteSingleValue(object operand, CalcEvaluatorContext context)
        {
            double num;

            if (operand is TimeSpan)
            {
                try
                {
                    TimeSpan span = (TimeSpan)operand;
                    return(span.Negate());
                }
                catch (OverflowException)
                {
                    return(CalcErrors.Number);
                }
            }
            if (CalcConvert.TryToDouble(operand, out num, true))
            {
                return((double)-num);
            }
            return(CalcErrors.Value);
        }
示例#7
0
        internal object EvaluteInternal(object operand, CalcEvaluatorContext context)
        {
            CalcArray     array     = operand as CalcArray;
            CalcReference reference = operand as CalcReference;

            if (reference != null)
            {
                array = CalcConvert.ToArray(reference);
            }
            if (array == null)
            {
                return(this.EvaluteSingleValue(operand, context));
            }
            if (array.Length < 1)
            {
                return(CalcErrors.Number);
            }
            object[,] values = new object[array.RowCount, array.ColumnCount];
            CalcOperator.OperatorArray array2 = new CalcOperator.OperatorArray(values);
            object obj2 = array.GetValue(0);
            Type   type = (obj2 != null) ? obj2.GetType() : typeof(object);

            for (int i = 0; i < array.RowCount; i++)
            {
                for (int j = 0; j < array.ColumnCount; j++)
                {
                    object obj3 = array.GetValue(i, j);
                    if ((obj3 != null) && (obj3.GetType() != type))
                    {
                        return(CalcErrors.Number);
                    }
                    object obj4 = this.EvaluteSingleValue(obj3, context);
                    values[i, j] = obj4;
                }
            }
            return(array2);
        }
示例#8
0
        internal object EvaluteInternal(object left, object right, CalcEvaluatorContext context)
        {
            bool flag  = CalcHelper.TryExtractToSingleValue(left, out left);
            bool flag2 = CalcHelper.TryExtractToSingleValue(right, out right);

            if (flag && flag2)
            {
                return(this.EvaluteSingleValue(left, right));
            }
            int num  = flag ? -1 : (left as CalcArray).RowCount;
            int num2 = flag ? -1 : (left as CalcArray).ColumnCount;
            int num3 = flag2 ? -1 : (right as CalcArray).RowCount;
            int num4 = flag2 ? -1 : (right as CalcArray).ColumnCount;
            int num5 = -1;
            int num6 = -1;

            if (!flag)
            {
                num5 = num;
                num6 = num2;
            }
            if (!flag2)
            {
                num5 = (num5 == -1) ? num3 : ((num3 > 1) ? ((num5 > 1) ? Math.Min(num3, num5) : num3) : num5);
                num6 = (num6 == -1) ? num4 : ((num4 > 1) ? ((num6 > 1) ? Math.Min(num4, num6) : num4) : num6);
            }
            object[,] values = new object[num5, num6];
            for (int i = 0; i < num5; i++)
            {
                for (int j = 0; j < num6; j++)
                {
                    values[i, j] = this.EvaluteSingleValue(flag ? left : CalcHelper.GetArrayValue(left as CalcArray, i, j), flag2 ? right : CalcHelper.GetArrayValue(right as CalcArray, i, j));
                }
            }
            return(new ConcreteArray <object>(values));
        }
示例#9
0
 internal virtual object EvaluteSingleValue(object operand, CalcEvaluatorContext context)
 {
     throw new InvalidOperationException();
 }
示例#10
0
 /// <summary>
 /// Returns the result of the operator applied to the operand.
 /// </summary>
 /// <param name="operand">
 /// Operand for the operator evaluation.
 /// </param>
 /// <param name="context">
 /// The <see cref="T:Dt.CalcEngine.CalcEvaluatorContext" /> associate with the operator evaluation.
 /// </param>
 /// <returns>
 /// Result of the operator applied to the operand.
 /// </returns>
 public abstract object Evaluate(object operand, CalcEvaluatorContext context);
示例#11
0
 /// <summary>
 /// Returns the result of the operator applied to the operands.
 /// </summary>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand..</param>
 /// <param name="context">
 /// The <see cref="T:Dt.CalcEngine.CalcEvaluatorContext" /> associate with the operator evaluation.
 /// </param>
 /// <returns>
 /// Result of the operator applied to the operand.
 /// </returns>
 public override object Evaluate(object left, object right, CalcEvaluatorContext context)
 {
     return(base.EvaluteInternal(left, right, context));
 }
示例#12
0
 /// <summary>
 /// Returns the result of the operator applied to the operand.
 /// </summary>
 /// <param name="operand">
 /// Operand for the operator evaluation.
 /// </param>
 /// <param name="context">
 /// The <see cref="T:Dt.CalcEngine.CalcEvaluatorContext" /> associate with the operator evaluation.
 /// </param>
 /// <returns>
 /// Result of the operator applied to the operand.
 /// </returns>
 public override object Evaluate(object operand, CalcEvaluatorContext context)
 {
     return(base.EvaluteInternal(operand, context));
 }
示例#13
0
        public static void ExtractAllReferenceExpression(ICalcEvaluator evaluator, CalcExpression root, List <CalcReferenceExpression> nodes)
        {
            if (root is CalcBinaryOperatorExpression)
            {
                CalcBinaryOperatorExpression expression = root as CalcBinaryOperatorExpression;
                ExtractAllReferenceExpression(evaluator, expression.Left, nodes);
                ExtractAllReferenceExpression(evaluator, expression.Right, nodes);
            }
            else if (root is CalcParenthesesExpression)
            {
                CalcParenthesesExpression expression2 = root as CalcParenthesesExpression;
                ExtractAllReferenceExpression(evaluator, expression2.Arg, nodes);
            }
            else if (root is CalcExternalNameExpression)
            {
                CalcExternalNameExpression expression3 = root as CalcExternalNameExpression;
                ICalcSource source = expression3.Source;
                if (source != null)
                {
                    CalcExpression expression4 = source.GetDefinedName(expression3.Name, -1, -1);
                    if (expression4 != null)
                    {
                        ExtractAllReferenceExpression(evaluator, expression4, nodes);
                    }
                }
            }
            else if (root is CalcFunctionExpression)
            {
                CalcFunctionExpression expr = root as CalcFunctionExpression;
                Worksheet worksheet         = evaluator as Worksheet;
                if (worksheet != null)
                {
                    CalcEvaluatorContext context = new CalcEvaluatorContext(worksheet, false, worksheet.ActiveRowIndex, worksheet.ActiveColumnIndex, 1, 1);
                    object obj2 = new CalcEvaluator().Evaluate(expr, context, true, true);
                    if (obj2 is CalcReference)
                    {
                        CalcReference reference   = obj2 as CalcReference;
                        int           row         = reference.GetRow(0);
                        int           rowCount    = reference.GetRowCount(0);
                        int           column      = reference.GetColumn(0);
                        int           columnCount = reference.GetColumnCount(0);
                        ICalcSource   source2     = null;
                        CalcReference reference2  = reference.GetSource();

                        // hdt
                        MethodInfo info = reference2.GetType().GetRuntimeMethod("GetContext", null);

                        if (info != null)
                        {
                            source2 = info.Invoke(reference2, null) as ICalcSource;
                        }
                        if (source2 == null)
                        {
                            source2 = worksheet;
                        }
                        CalcExternalRangeExpression expression6 = CreateExternalRangeExpressionByCount(source2, row, column, rowCount, columnCount, false, false, false, false);
                        nodes.Add(expression6);
                    }
                }
            }
            else if (root is CalcReferenceExpression)
            {
                nodes.Add(root as CalcReferenceExpression);
            }
        }
示例#14
0
 /// <summary>
 /// Returns the result of the operator applied to the operands.
 /// </summary>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand..</param>
 /// <param name="context">
 /// The <see cref="T:Dt.CalcEngine.CalcEvaluatorContext" /> associate with the operator evaluation.
 /// </param>
 /// <returns>
 /// Result of the operator applied to the operand.
 /// </returns>
 public abstract object Evaluate(object left, object right, CalcEvaluatorContext context);