예제 #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.Core.SS.Formula.Functions.Function result = _instancesByPtgClass[ptg] as Npoi.Core.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.Core.SS.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_INDIRECT:
                    return(Indirect.instance.Evaluate(args, ec));

                case Npoi.Core.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 + ")");
        }
예제 #2
0
 private static void Add(Dictionary <OperationPtg, object> m, OperationPtg ptgKey,
                         Npoi.Core.SS.Formula.Functions.Function instance)
 {
     // make sure ptg has single private constructor because map lookups assume singleton keys
     ConstructorInfo[] cc = ptgKey.GetType().GetTypeInfo().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;
 }