@@ -1314,10 +1314,22 @@ Expression ParseNew()
1314
1314
if ( _textParser . CurrentToken . Id == TokenId . Identifier )
1315
1315
{
1316
1316
var newTypeName = _textParser . CurrentToken . Text ;
1317
+ _textParser . NextToken ( ) ;
1318
+
1319
+ while ( _textParser . CurrentToken . Id == TokenId . Dot || _textParser . CurrentToken . Id == TokenId . Plus )
1320
+ {
1321
+ var sep = _textParser . CurrentToken . Text ;
1322
+ _textParser . NextToken ( ) ;
1323
+ if ( _textParser . CurrentToken . Id != TokenId . Identifier )
1324
+ throw ParseError ( Res . IdentifierExpected ) ;
1325
+ newTypeName += sep + _textParser . CurrentToken . Text ;
1326
+ _textParser . NextToken ( ) ;
1327
+ }
1328
+
1317
1329
newType = FindType ( newTypeName ) ;
1318
1330
if ( newType == null )
1319
1331
throw ParseError ( _textParser . CurrentToken . Pos , Res . TypeNotFound , newTypeName ) ;
1320
- _textParser . NextToken ( ) ;
1332
+
1321
1333
if ( _textParser . CurrentToken . Id != TokenId . OpenParen &&
1322
1334
_textParser . CurrentToken . Id != TokenId . OpenBracket &&
1323
1335
_textParser . CurrentToken . Id != TokenId . OpenCurlyParen )
@@ -1414,9 +1426,13 @@ private Expression CreateNewExpression(List<DynamicProperty> properties, List<Ex
1414
1426
#endif
1415
1427
type = typeof ( DynamicClass ) ;
1416
1428
Type typeForKeyValuePair = typeof ( KeyValuePair < string , object > ) ;
1429
+ #if NET35 || NET40
1430
+ ConstructorInfo constructorForKeyValuePair =
1431
+ typeForKeyValuePair . GetConstructors ( ) . First ( ) ;
1432
+ #else
1417
1433
ConstructorInfo constructorForKeyValuePair =
1418
1434
typeForKeyValuePair . GetTypeInfo ( ) . DeclaredConstructors . First ( ) ;
1419
-
1435
+ #endif
1420
1436
var arrayIndexParams = new List < Expression > ( ) ;
1421
1437
for ( int i = 0 ; i < expressions . Count ; i ++ )
1422
1438
{
@@ -1433,7 +1449,11 @@ private Expression CreateNewExpression(List<DynamicProperty> properties, List<Ex
1433
1449
Expression . NewArrayInit ( typeof ( KeyValuePair < string , object > ) , arrayIndexParams ) ;
1434
1450
1435
1451
// Get the "public DynamicClass(KeyValuePair<string, object>[] propertylist)" constructor
1452
+ #if NET35 || NET40
1453
+ ConstructorInfo constructor = type . GetConstructors ( ) . First ( ) ;
1454
+ #else
1436
1455
ConstructorInfo constructor = type . GetTypeInfo ( ) . DeclaredConstructors . First ( ) ;
1456
+ #endif
1437
1457
return Expression . New ( constructor , newArrayExpression ) ;
1438
1458
#if ! UAP10_0
1439
1459
}
@@ -1446,7 +1466,7 @@ private Expression CreateNewExpression(List<DynamicProperty> properties, List<Ex
1446
1466
1447
1467
Type [ ] propertyTypes = type . GetProperties ( ) . Select ( p => p . PropertyType ) . ToArray ( ) ;
1448
1468
ConstructorInfo ctor = type . GetConstructor ( propertyTypes ) ;
1449
- if ( ctor ! = null )
1469
+ if ( ctor ! = null && ctor . GetParameters ( ) . Length == expressions . Count )
1450
1470
return Expression . New ( ctor , expressions ) ;
1451
1471
1452
1472
MemberBinding [ ] bindings = new MemberBinding [ properties . Count ] ;
0 commit comments