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,8 +106,9 @@ 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
111+ { "$(FRAMEWORK)" , IronPython . Runtime . ClrModule . TargetFramework } ,
110112 { "$(IS_NETCOREAPP)" , IronPython . Runtime . ClrModule . IsNetCoreApp . ToString ( ) } ,
111113 { "$(IS_NETSTANDARD)" , IronPython . Runtime . ClrModule . TargetFramework . StartsWith ( ".NETStandard" , StringComparison . Ordinal ) . ToString ( ) } ,
112114 { "$(IS_MONO)" , IronPython . Runtime . ClrModule . IsMono . ToString ( ) } ,
@@ -119,20 +121,20 @@ private bool EvaluateExpression(string expression) {
119121 // operators
120122 { "==" , "=" } ,
121123 { "||" , "OR" } ,
124+ { "\" " , "'" } , // replace double quotes before double-double quotes
122125 { "\" \" " , "\" " } ,
123- { "\" " , "'" } ,
124126 { "&&" , "AND" } ,
125- { "!=" , "<>" }
127+ { "!=" , "<>" } ,
126128 } ;
127129
128- foreach ( var replacement in replacements ) {
129- expression = expression . Replace ( replacement . Key , replacement . Value ) ;
130+ foreach ( DictionaryEntry replacement in replacements ) {
131+ expression = expression . Replace ( ( string ) replacement . Key , replacement . Value ? . ToString ( ) ) ;
130132 }
131133
132134 try {
133135 object res = dummy . Compute ( expression , null ) ;
134- if ( res is bool ) {
135- return ( bool ) res ;
136+ if ( res is bool result ) {
137+ return result ;
136138 }
137139 } catch ( EvaluateException ex ) {
138140 if ( ex . Message . StartsWith ( "The expression contains undefined function call" , StringComparison . Ordinal ) )
0 commit comments