Skip to content

Commit b5c1bdb

Browse files
committed
- fix BindingRestrictions for functions with variable arguments, e.g. Contains(variable)
1 parent f3141e3 commit b5c1bdb

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/Simple.OData.Client.Dynamic/DynamicODataExpression.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Dynamic;
44
using System.Linq;
@@ -91,12 +91,12 @@ public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
9191
public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value)
9292
{
9393
var ctor = CtorWithStringAndValue;
94-
Expression objectExpression = value.Expression;
95-
if ((value.Value != null && value.Value.GetType().IsValue()) ||
96-
(value.Value == null && Nullable.GetUnderlyingType(objectExpression.Type) != null))
97-
{
98-
objectExpression = Expression.Convert(objectExpression, typeof(object));
99-
}
94+
Expression objectExpression = value.Expression;
95+
if ((value.Value != null && value.Value.GetType().IsValue()) ||
96+
(value.Value == null && Nullable.GetUnderlyingType(objectExpression.Type) != null))
97+
{
98+
objectExpression = Expression.Convert(objectExpression, typeof(object));
99+
}
100100
var ctorArguments = new[] { Expression.Constant(binder.Name), objectExpression };
101101

102102
return new DynamicMetaObject(
@@ -112,13 +112,13 @@ public override DynamicMetaObject BindInvokeMember(
112112
var expression = Expression.New(CtorWithExpressionAndExpressionFunction,
113113
new[]
114114
{
115-
Expression.Constant(this.Value),
115+
Expression.Constant(this.Value),
116116
Expression.Constant(new ExpressionFunction(binder.Name, args.Select(x => x.Value)))
117-
});
118-
117+
}) ;
118+
BindingRestrictions bindingRestrictions = args.Aggregate(BindingRestrictions.Empty, (acc, x) => acc.Merge(BindingRestrictions.GetInstanceRestriction(x.Expression, x.Value)));
119119
return new DynamicMetaObject(
120120
expression,
121-
BindingRestrictions.GetTypeRestriction(Expression, LimitType));
121+
bindingRestrictions);
122122
}
123123
else if (string.Equals(binder.Name, ODataLiteral.Any, StringComparison.OrdinalIgnoreCase) ||
124124
string.Equals(binder.Name, ODataLiteral.All, StringComparison.OrdinalIgnoreCase))

0 commit comments

Comments
 (0)