Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2017-01-04 00:26:24 +0300
committerGitHub <noreply@github.com>2017-01-04 00:26:24 +0300
commit58ecf58218afebf1d5e4659e0a6d445a69c15782 (patch)
treec3e85ea8a28f97c45a9ce3ce2b9c7c7ae2aa2758 /src
parent14705f76a90f2eb777082ac98e229213e3ebaa96 (diff)
parent4492c73d9b034e5b96ec4f3dded0617606f7f403 (diff)
Merge pull request #14685 from hughbe/binary-dynamic-test
Add regression test for DynamicExpression in BinaryOperationBinder
Diffstat (limited to 'src')
-rw-r--r--src/System.Linq.Expressions/tests/Dynamic/BinaryOperationTests.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/System.Linq.Expressions/tests/Dynamic/BinaryOperationTests.cs b/src/System.Linq.Expressions/tests/Dynamic/BinaryOperationTests.cs
index e71f3ab41c..9fb4490e5d 100644
--- a/src/System.Linq.Expressions/tests/Dynamic/BinaryOperationTests.cs
+++ b/src/System.Linq.Expressions/tests/Dynamic/BinaryOperationTests.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
+using System.Linq.Expressions.Tests;
using Microsoft.CSharp.RuntimeBinder;
using Xunit;
@@ -698,5 +699,37 @@ namespace System.Dynamic.Tests
dY = 49;
Assert.Throws<RuntimeBinderException>(() => dX && dY);
}
+
+ [Theory]
+ [ClassData(typeof(CompilationTypes))]
+ public void BinaryCallSiteBinder_DynamicExpression(bool useInterpreter)
+ {
+ DynamicExpression expression = DynamicExpression.Dynamic(
+ new BinaryCallSiteBinder(),
+ typeof(object),
+ Expression.Constant(40, typeof(object)),
+ Expression.Constant(2, typeof(object)));
+ Func<object> func = Expression.Lambda<Func<object>>(expression).Compile(useInterpreter);
+ Assert.Equal("42", func().ToString());
+ }
+
+ private class BinaryCallSiteBinder : BinaryOperationBinder
+ {
+ public BinaryCallSiteBinder() : base(ExpressionType.Add) {}
+
+ public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
+ {
+ return new DynamicMetaObject(
+ Expression.Convert(
+ Expression.Add(
+ Expression.Convert(target.Expression, typeof(int)),
+ Expression.Convert(arg.Expression, typeof(int))
+ ), typeof(object)),
+
+ BindingRestrictions.GetTypeRestriction(target.Expression, typeof(int)).Merge(
+ BindingRestrictions.GetTypeRestriction(arg.Expression, typeof(int))
+ ));
+ }
+ }
}
}