Skip to content

Commit aebdd1b

Browse files
committed
Better support of new with anonymous types, so it looks more like when you use a real expression
1 parent 9585b9f commit aebdd1b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/System.Linq.Dynamic.Core/ExpressionParser.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1464,10 +1464,23 @@ private Expression CreateNewExpression(List<DynamicProperty> properties, List<Ex
14641464
#endif
14651465
}
14661466

1467-
Type[] propertyTypes = type.GetProperties().Select(p => p.PropertyType).ToArray();
1467+
IEnumerable<PropertyInfo> propertyInfos = type.GetProperties();
1468+
#if !UAP10_0 && !NET35 && !NETSTANDARD1_3
1469+
if (type.BaseType == typeof(DynamicClass))
1470+
{
1471+
propertyInfos = propertyInfos.Where(x => x.Name != "Item");
1472+
}
1473+
#elif NETSTANDARD
1474+
if (type.GetTypeInfo().BaseType == typeof(DynamicClass))
1475+
{
1476+
propertyInfos = propertyInfos.Where(x => x.Name != "Item");
1477+
}
1478+
#endif
1479+
1480+
Type[] propertyTypes = propertyInfos.Select(p => p.PropertyType).ToArray();
14681481
ConstructorInfo ctor = type.GetConstructor(propertyTypes);
14691482
if (ctor != null && ctor.GetParameters().Length == expressions.Count)
1470-
return Expression.New(ctor, expressions);
1483+
return Expression.New(ctor, expressions, (IEnumerable<MemberInfo>) propertyInfos);
14711484

14721485
MemberBinding[] bindings = new MemberBinding[properties.Count];
14731486
for (int i = 0; i < bindings.Length; i++)

0 commit comments

Comments
 (0)