Beispiel #1
0
        /**
         * returns the OperationEval concrete impl instance corresponding
         * to the supplied operationPtg
         */
        public static ValueEval Evaluate(OperationPtg ptg, ValueEval[] args,
                                         OperationEvaluationContext ec)
        {
            if (ptg == null)
            {
                throw new ArgumentException("ptg must not be null");
            }
            NPOI.SS.Formula.Functions.Function result = _instancesByPtgClass[ptg] as NPOI.SS.Formula.Functions.Function;

            if (result != null)
            {
                return(result.Evaluate(args, ec.RowIndex, (short)ec.ColumnIndex));
            }

            if (ptg is AbstractFunctionPtg)
            {
                AbstractFunctionPtg fptg = (AbstractFunctionPtg)ptg;
                int functionIndex        = fptg.FunctionIndex;
                switch (functionIndex)
                {
                case NPOI.SS.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_INDIRECT:
                    return(Indirect.instance.Evaluate(args, ec));

                case NPOI.SS.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_EXTERNAL:
                    return(UserDefinedFunction.instance.Evaluate(args, ec));
                }

                return(FunctionEval.GetBasicFunction(functionIndex).Evaluate(args, ec.RowIndex, ec.ColumnIndex));
            }
            throw new Exception("Unexpected operation ptg class (" + ptg.GetType().Name + ")");
        }
Beispiel #2
0
 private static void Add(Hashtable m, OperationPtg ptgKey,
                         NPOI.SS.Formula.Functions.Function instance)
 {
     // make sure ptg has single private constructor because map lookups assume singleton keys
     ConstructorInfo[] cc = ptgKey.GetType().GetConstructors();
     if (cc.Length > 1 || (cc.Length > 0 && !cc[0].IsPrivate))
     {
         throw new Exception("Failed to verify instance ("
                             + ptgKey.GetType().Name + ") is a singleton.");
     }
     m[ptgKey] = instance;
 }
        /**
         * returns the OperationEval concrete impl instance corresponding
         * to the supplied operationPtg
         */
        public static ValueEval Evaluate(OperationPtg ptg, ValueEval[] args,
                                         OperationEvaluationContext ec)
        {
            if (ptg == null)
            {
                throw new ArgumentException("ptg must not be null");
            }
            NPOI.SS.Formula.Functions.Function result = _instancesByPtgClass[ptg] as NPOI.SS.Formula.Functions.Function;

            FreeRefFunction udfFunc = null;

            if (result == null)
            {
                if (ptg is AbstractFunctionPtg)
                {
                    AbstractFunctionPtg fptg = (AbstractFunctionPtg)ptg;
                    int functionIndex        = fptg.FunctionIndex;
                    switch (functionIndex)
                    {
                    case NPOI.SS.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_INDIRECT:
                        udfFunc = Indirect.instance;
                        break;

                    case NPOI.SS.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_EXTERNAL:
                        udfFunc = UserDefinedFunction.instance;
                        break;

                    default:
                        result = FunctionEval.GetBasicFunction(functionIndex);
                        break;
                    }
                }
            }

            if (result != null)
            {
                if (result is ArrayFunction)
                {
                    ArrayFunction func = (ArrayFunction)result;
                    ValueEval     eval = EvaluateArrayFunction(func, args, ec);
                    if (eval != null)
                    {
                        return(eval);
                    }
                }
                return(result.Evaluate(args, ec.RowIndex, (short)ec.ColumnIndex));
            }
            else if (udfFunc != null)
            {
                return(udfFunc.Evaluate(args, ec));
            }
            throw new Exception("Unexpected operation ptg class (" + ptg.GetType().Name + ")");
        }