55using System ;
66using System . Collections ;
77using System . Collections . Generic ;
8+ using System . Collections . Specialized ;
89using System . Data ;
910using System . IO ;
1011using System . Runtime . InteropServices ;
@@ -105,7 +106,7 @@ protected bool ConditionMatched(string condition) {
105106 private bool EvaluateExpression ( string expression ) {
106107 var dummy = new DataTable ( ) ;
107108 string filter = expression ;
108- var replacements = new Dictionary < string , string > ( ) {
109+ var replacements = new OrderedDictionary ( ) {
109110 // variables
110111 { "$(IS_NETCOREAPP)" , IronPython . Runtime . ClrModule . IsNetCoreApp . ToString ( ) } ,
111112 { "$(IS_NETSTANDARD)" , IronPython . Runtime . ClrModule . TargetFramework . StartsWith ( ".NETStandard" , StringComparison . Ordinal ) . ToString ( ) } ,
@@ -119,20 +120,20 @@ private bool EvaluateExpression(string expression) {
119120 // operators
120121 { "==" , "=" } ,
121122 { "||" , "OR" } ,
123+ { "\" " , "'" } , // replace double quotes before double-double quotes
122124 { "\" \" " , "\" " } ,
123- { "\" " , "'" } ,
124125 { "&&" , "AND" } ,
125- { "!=" , "<>" }
126+ { "!=" , "<>" } ,
126127 } ;
127128
128- foreach ( var replacement in replacements ) {
129- expression = expression . Replace ( replacement . Key , replacement . Value ) ;
129+ foreach ( DictionaryEntry replacement in replacements ) {
130+ expression = expression . Replace ( ( string ) replacement . Key , replacement . Value ? . ToString ( ) ) ;
130131 }
131132
132133 try {
133134 object res = dummy . Compute ( expression , null ) ;
134- if ( res is bool ) {
135- return ( bool ) res ;
135+ if ( res is bool result ) {
136+ return result ;
136137 }
137138 } catch ( EvaluateException ex ) {
138139 if ( ex . Message . StartsWith ( "The expression contains undefined function call" , StringComparison . Ordinal ) )
0 commit comments