@@ -1400,40 +1400,30 @@ private Expression CreateNewExpression(List<DynamicProperty> properties, List<Ex
14001400
14011401 if ( type == null )
14021402 {
1403- #if ! UAP10_0
1404- if ( _parsingConfig != null && _parsingConfig . UseDynamicObjectClassForAnonymousTypes )
1405- {
1406- #endif
1407- type = typeof ( DynamicClass ) ;
1408- Type typeForKeyValuePair = typeof ( KeyValuePair < string , object > ) ;
1409- #if NET35 || NET40
1410- ConstructorInfo constructorForKeyValuePair = typeForKeyValuePair . GetConstructors ( ) . First ( ) ;
1411- #else
1412- ConstructorInfo constructorForKeyValuePair = typeForKeyValuePair . GetTypeInfo ( ) . DeclaredConstructors . First ( ) ;
1413- #endif
1414- var arrayIndexParams = new List < Expression > ( ) ;
1415- for ( int i = 0 ; i < expressions . Count ; i ++ )
1416- {
1417- // Just convert the expression always to an object expression.
1418- UnaryExpression boxingExpression = Expression . Convert ( expressions [ i ] , typeof ( object ) ) ;
1419- NewExpression parameter = Expression . New ( constructorForKeyValuePair , ( Expression ) Expression . Constant ( properties [ i ] . Name ) , boxingExpression ) ;
1403+ #if UAP10_0
1404+ type = typeof ( DynamicClass ) ;
1405+ Type typeForKeyValuePair = typeof ( KeyValuePair < string , object > ) ;
14201406
1421- arrayIndexParams . Add ( parameter ) ;
1422- }
1407+ ConstructorInfo constructorForKeyValuePair = typeForKeyValuePair . GetTypeInfo ( ) . DeclaredConstructors . First ( ) ;
14231408
1424- // Create an expression tree that represents creating and initializing a one-dimensional array of type KeyValuePair<string, object>.
1425- NewArrayExpression newArrayExpression = Expression . NewArrayInit ( typeof ( KeyValuePair < string , object > ) , arrayIndexParams ) ;
1409+ var arrayIndexParams = new List < Expression > ( ) ;
1410+ for ( int i = 0 ; i < expressions . Count ; i ++ )
1411+ {
1412+ // Just convert the expression always to an object expression.
1413+ UnaryExpression boxingExpression = Expression . Convert ( expressions [ i ] , typeof ( object ) ) ;
1414+ NewExpression parameter = Expression . New ( constructorForKeyValuePair , ( Expression ) Expression . Constant ( properties [ i ] . Name ) , boxingExpression ) ;
14261415
1427- // Get the "public DynamicClass(KeyValuePair<string, object>[] propertylist)" constructor
1428- #if NET35 || NET40
1429- ConstructorInfo constructor = type . GetConstructors ( ) . First ( ) ;
1430- #else
1431- ConstructorInfo constructor = type . GetTypeInfo ( ) . DeclaredConstructors . First ( ) ;
1432- #endif
1433- return Expression . New ( constructor , newArrayExpression ) ;
1434- #if ! UAP10_0
1416+ arrayIndexParams . Add ( parameter ) ;
14351417 }
14361418
1419+ // Create an expression tree that represents creating and initializing a one-dimensional array of type KeyValuePair<string, object>.
1420+ NewArrayExpression newArrayExpression = Expression . NewArrayInit ( typeof ( KeyValuePair < string , object > ) , arrayIndexParams ) ;
1421+
1422+ // Get the "public DynamicClass(KeyValuePair<string, object>[] propertylist)" constructor
1423+ ConstructorInfo constructor = type . GetTypeInfo ( ) . DeclaredConstructors . First ( ) ;
1424+
1425+ return Expression . New ( constructor , newArrayExpression ) ;
1426+ #else
14371427 type = DynamicClassFactory . CreateType ( properties , _createParameterCtor ) ;
14381428#endif
14391429 }
@@ -1454,7 +1444,6 @@ private Expression CreateNewExpression(List<DynamicProperty> properties, List<Ex
14541444 for ( int i = 0 ; i < propertyTypes . Length ; i ++ )
14551445 {
14561446 Type propertyType = propertyTypes [ i ] ;
1457- // Type expressionType = expressions[i].Type;
14581447
14591448 // Promote from Type to Nullable Type if needed
14601449 expressionsPromoted . Add ( _parsingConfig . ExpressionPromoter . Promote ( expressions [ i ] , propertyType , true , true ) ) ;
@@ -1468,7 +1457,6 @@ private Expression CreateNewExpression(List<DynamicProperty> properties, List<Ex
14681457 {
14691458 PropertyInfo property = type . GetProperty ( properties [ i ] . Name ) ;
14701459 Type propertyType = property . PropertyType ;
1471- // Type expressionType = expressions[i].Type;
14721460
14731461 // Promote from Type to Nullable Type if needed
14741462 bindings [ i ] = Expression . Bind ( property , _parsingConfig . ExpressionPromoter . Promote ( expressions [ i ] , propertyType , true , true ) ) ;
0 commit comments