@@ -17,9 +17,10 @@ public IExpressionNode CreateTree(
1717 String expression ,
1818 ITraceWriter trace ,
1919 IEnumerable < INamedValueInfo > namedValues ,
20- IEnumerable < IFunctionInfo > functions )
20+ IEnumerable < IFunctionInfo > functions ,
21+ Boolean allowCaseFunction = true )
2122 {
22- var context = new ParseContext ( expression , trace , namedValues , functions ) ;
23+ var context = new ParseContext ( expression , trace , namedValues , functions , allowCaseFunction ) ;
2324 context . Trace . Info ( $ "Parsing expression: <{ expression } >") ;
2425 return CreateTree ( context ) ;
2526 }
@@ -349,6 +350,10 @@ private static void FlushTopEndParameters(ParseContext context)
349350 {
350351 throw new ParseException ( ParseExceptionKind . TooManyParameters , token : @operator , expression : context . Expression ) ;
351352 }
353+ else if ( functionInfo . Name . Equals ( "case" , StringComparison . OrdinalIgnoreCase ) && function . Parameters . Count % 2 == 0 )
354+ {
355+ throw new ParseException ( ParseExceptionKind . EvenParameters , token : @operator , expression : context . Expression ) ;
356+ }
352357 }
353358
354359 /// <summary>
@@ -411,13 +416,20 @@ private static Boolean TryGetFunctionInfo(
411416 String name ,
412417 out IFunctionInfo functionInfo )
413418 {
419+ if ( String . Equals ( name , "case" , StringComparison . OrdinalIgnoreCase ) && ! context . AllowCaseFunction )
420+ {
421+ functionInfo = null ;
422+ return false ;
423+ }
424+
414425 return ExpressionConstants . WellKnownFunctions . TryGetValue ( name , out functionInfo ) ||
415426 context . ExtensionFunctions . TryGetValue ( name , out functionInfo ) ;
416427 }
417428
418429 private sealed class ParseContext
419430 {
420431 public Boolean AllowUnknownKeywords ;
432+ public Boolean AllowCaseFunction ;
421433 public readonly String Expression ;
422434 public readonly Dictionary < String , IFunctionInfo > ExtensionFunctions = new Dictionary < String , IFunctionInfo > ( StringComparer . OrdinalIgnoreCase ) ;
423435 public readonly Dictionary < String , INamedValueInfo > ExtensionNamedValues = new Dictionary < String , INamedValueInfo > ( StringComparer . OrdinalIgnoreCase ) ;
@@ -433,7 +445,8 @@ public ParseContext(
433445 ITraceWriter trace ,
434446 IEnumerable < INamedValueInfo > namedValues ,
435447 IEnumerable < IFunctionInfo > functions ,
436- Boolean allowUnknownKeywords = false )
448+ Boolean allowUnknownKeywords = false ,
449+ Boolean allowCaseFunction = true )
437450 {
438451 Expression = expression ?? String . Empty ;
439452 if ( Expression . Length > ExpressionConstants . MaxLength )
@@ -454,6 +467,7 @@ public ParseContext(
454467
455468 LexicalAnalyzer = new LexicalAnalyzer ( Expression ) ;
456469 AllowUnknownKeywords = allowUnknownKeywords ;
470+ AllowCaseFunction = allowCaseFunction ;
457471 }
458472
459473 private class NoOperationTraceWriter : ITraceWriter
0 commit comments