@@ -42,6 +42,8 @@ public class ExpressionEvaluator
42
42
private static readonly Regex stringBeginningForEndBlockRegex = new Regex ( "[$]?[@]?[\" ]$" ) ;
43
43
private static readonly Regex lambdaExpressionRegex = new Regex ( @"^\s*(?<args>(\s*[(]\s*([" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9]*\s*([,]\s*[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9]*\s*)*)?[)])|[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9]*)\s*=>(?<expression>.*)$" , RegexOptions . Singleline ) ;
44
44
private static readonly Regex lambdaArgRegex = new Regex ( @"[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9]*" ) ;
45
+ private static readonly Regex initInNewBeginningRegex = new Regex ( @"^\s*{" ) ;
46
+ private static readonly Regex OtherDimentionArrayInNewBeginningRegex = new Regex ( @"^\s*\[" ) ;
45
47
46
48
private static readonly string instanceCreationWithNewKeywordRegexPattern = @"^new\s+(?<name>[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9.]*)\s*(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?\s*((?<isfunction>[(])|(?<isArray>\[))?" ;
47
49
private Regex instanceCreationWithNewKeywordRegex = new Regex ( instanceCreationWithNewKeywordRegexPattern ) ;
@@ -1365,22 +1367,33 @@ private bool EvaluateInstanceCreationWithNewKeyword(string expr, string restOfEx
1365
1367
else if ( instanceCreationMatch . Groups [ "isArray" ] . Success )
1366
1368
{
1367
1369
List < string > arrayArgs = GetExpressionsBetweenParenthesesOrOtherImbricableBrackets ( expr , ref i , true , "," , "[" , "]" ) ;
1370
+ i ++ ;
1371
+ Array array = null ;
1368
1372
1369
1373
if ( arrayArgs . Count > 0 )
1370
1374
{
1371
- stack . Push ( Array . CreateInstance ( type , arrayArgs . ConvertAll ( subExpression => ( int ) Evaluate ( subExpression ) ) . ToArray ( ) ) ) ;
1375
+ array = Array . CreateInstance ( type , arrayArgs . ConvertAll ( subExpression => ( int ) Evaluate ( subExpression ) ) . ToArray ( ) ) ;
1372
1376
}
1373
- else
1377
+
1378
+ Match initInNewBeginningMatch = initInNewBeginningRegex . Match ( expr . Substring ( i ) ) ;
1379
+
1380
+ if ( initInNewBeginningMatch . Success )
1374
1381
{
1375
- //int[,] test = new int[4, 2] ;
1382
+ i += initInNewBeginningMatch . Length ;
1376
1383
1377
- //Array.CreateInstance()
1384
+ List < string > arrayElements = GetExpressionsBetweenParenthesesOrOtherImbricableBrackets ( expr , ref i , true , "," , "{" , "}" ) ;
1385
+ i ++ ;
1386
+
1387
+ if ( array == null )
1388
+ array = Array . CreateInstance ( type , arrayElements . Count ) ;
1378
1389
1379
- //test[0, 1] = 3 ;
1390
+ Array . Copy ( arrayElements . ConvertAll ( subExpression => Evaluate ( subExpression ) ) . ToArray ( ) , array , arrayElements . Count ) ;
1380
1391
}
1392
+
1393
+ stack . Push ( array ) ;
1381
1394
}
1382
1395
else
1383
- throw new ExpressionEvaluatorSyntaxErrorException ( $ "A new expression requires that type be followed by (), [], or { "{}" } (Check : { instanceCreationMatch . Value } )") ;
1396
+ throw new ExpressionEvaluatorSyntaxErrorException ( $ "A new expression requires that type be followed by () or [] (Check : { instanceCreationMatch . Value } )") ;
1384
1397
1385
1398
return true ;
1386
1399
}
0 commit comments