Beispiel #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="expression">should be the of the function</param>
 /// <param name="parsingContext"></param>
 /// <param name="isNegated">True if the numeric result of the function should be negated.</param>
 public FunctionExpression(string expression, ParsingContext parsingContext, bool isNegated)
     : base(expression)
 {
     _parsingContext          = parsingContext;
     _functionCompilerFactory = new FunctionCompilerFactory(parsingContext.Configuration.FunctionRepository);
     _isNegated = isNegated;
     base.AddChild(new FunctionArgumentExpression(this));
 }
Beispiel #2
0
        public void CreateHandlesErrorFunctionCompiler()
        {
            var functionRepository      = FunctionRepository.Create();
            var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context);
            var function         = new IsError();
            var functionCompiler = functionCompilerFactory.Create(function);

            Assert.IsInstanceOfType(functionCompiler, typeof(ErrorHandlingFunctionCompiler));
        }
Beispiel #3
0
        public void CreateHandlesLookupFunctionCompiler()
        {
            var functionRepository      = FunctionRepository.Create();
            var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context);
            var function         = new Column();
            var functionCompiler = functionCompilerFactory.Create(function);

            Assert.IsInstanceOfType(functionCompiler, typeof(LookupFunctionCompiler));
        }
Beispiel #4
0
        public void CreateHandlesSpecialIfNaCompiler()
        {
            var functionRepository      = FunctionRepository.Create();
            var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context);
            var function         = new IfNa();
            var functionCompiler = functionCompilerFactory.Create(function);

            Assert.IsInstanceOfType(functionCompiler, typeof(IfNaFunctionCompiler));
        }
Beispiel #5
0
        public void CreateHandlesStandardFunctionCompiler()
        {
            var functionRepository      = FunctionRepository.Create();
            var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context);
            var function         = new Sum();
            var functionCompiler = functionCompilerFactory.Create(function);

            Assert.IsInstanceOfType(functionCompiler, typeof(DefaultCompiler));
        }
Beispiel #6
0
        public void CreateHandlesCustomFunctionCompiler()
        {
            var functionRepository = FunctionRepository.Create();

            functionRepository.LoadModule(new TestFunctionModule(_context));
            var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context);
            var function         = new MyFunction();
            var functionCompiler = functionCompilerFactory.Create(function);

            Assert.IsInstanceOfType(functionCompiler, typeof(MyFunctionCompiler));
        }
 public override bool Handle(string funcName, IEnumerable <Expression> children, ParsingContext context, out ExcelFunction function)
 {
     function = null;
     if (funcName.Contains(":OFFSET"))
     {
         var functionCompilerFactory = new FunctionCompilerFactory(context.Configuration.FunctionRepository, context);
         var startRange  = funcName.Split(':')[0];
         var c           = context.Scopes.Current;
         var resultRange = context.ExcelDataProvider.GetRange(c.Address.Worksheet, c.Address.FromRow, c.Address.FromCol, startRange);
         var rangeOffset = new RangeOffset
         {
             StartRange = resultRange
         };
         var compiler = functionCompilerFactory.Create(new Offset());
         children.First().Children.First().IgnoreCircularReference = true;
         var compileResult = compiler.Compile(children);
         rangeOffset.EndRange = compileResult.Result as ExcelDataProvider.IRangeInfo;
         function             = rangeOffset;
         return(true);
     }
     return(false);
 }