コード例 #1
0
        public string Evaluate(TagModel model)
        {
            var id = GetAutoValueAsString(nameof(Name), model);

            if (id == null)
            {
                throw ExpressionParseException.UnexpectedNullValue(nameof(Name)).Decorate(Name.Context);
            }
            id = LanguageHelper.CamelCaseAttribute(id);
            var raw = model.TryGet(id);

            if (raw == null)
            {
                throw MacroException.NotFound(id).Decorate(Name.Context);
            }
            var macro    = raw as DefineMacroTag.MarcoDefinition;
            var function = raw as DefineFunctionTag.FunctionDefinition;

            if (macro == null && function == null)
            {
                throw MacroException.NoMacroOrFunction(id).Decorate(Name.Context);
            }
            if (macro != null)
            {
                return(ExecuteMacro(model, id, macro));
            }
            return(ExecuteFunction(model, function));
        }
コード例 #2
0
 public void TestTooManyArguments()
 {
     try
     {
         new ExpressionLib().ParseAndEvaluate("fn:concat('abcd','ef', 'oops one extra')", new Reflection(this));
         Assert.Fail("Expected exception");
     }
     catch (ExpressionParseException EPe)
     {
         Assert.That(EPe.MessageWithOutContext,
                     Is.EqualTo(
                         ExpressionParseException.UnExpectedParameter(new Constant("oops one extra")).Message));
     }
 }
コード例 #3
0
 public void TestNotEnoughArguments()
 {
     try
     {
         new ExpressionLib().ParseAndEvaluate("fn:concat('abcd')", new Reflection(this));
         Assert.Fail("Expected exception");
     }
     catch (ExpressionParseException EPe)
     {
         Assert.That(EPe.MessageWithOutContext,
                     Is.EqualTo(
                         ExpressionParseException.ExpectedMoreParameter(new BaseFunctionLib().Obtain("concat"), 1, 2).Message));
     }
 }