Skip to content

Commit

Permalink
Fix for Codeplex Issue #38
Browse files Browse the repository at this point in the history
  • Loading branch information
RupertAvery committed Jan 23, 2016
1 parent 94370b1 commit 39dcf92
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ExpressionEvaluator/Parser/ExpressionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public static Expression GetMethod(Expression le, TypeOrGeneric member, IEnumera
{
type = le.Type;
instance = le;
isDynamic = type.IsDynamic();
isDynamic = IsDynamic(le);
}

if (isDynamic)
Expand Down Expand Up @@ -970,7 +970,7 @@ public static Expression BinaryOperator(Expression le, Expression re, Expression
{
// perform implicit conversion on known types

if (le.NodeType == ExpressionType.Dynamic || re.NodeType == ExpressionType.Dynamic)
if (IsDynamic(le) || IsDynamic(re))
{
if (expressionType == ExpressionType.OrElse)
{
Expand Down
37 changes: 37 additions & 0 deletions UnitTests/DynamicTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTestProject1.Domain;

namespace ExpressionEvaluator.Tests
{
public class DynamicContainer
{
public dynamic a { get; set; }
public dynamic b { get; set; }
public dynamic c(dynamic d, dynamic e)
{
return d + e;
}
}

[TestClass]
public class DynamicTests
{
[TestMethod]
public void CallMethodOnDynamicProperty()
{
dynamic invoice = new ExpandoObject();
invoice.Date = DateTime.Now;
var val = invoice.Date.ToString("mm/dd/yyyy");
var reg = new TypeRegistry();
reg.RegisterSymbol("invoice", invoice);
var expression = new CompiledExpression("invoice.Date.ToString(\"mm/dd/yyyy\")");
expression.TypeRegistry = reg;
var result2 = expression.Eval();
}

[TestMethod]
public void DynamicBinaryOperators()
{
var c = new DynamicContainer();
c.a = 1;
c.b = 2;
var actual = c.a + c.b - c.c(c.a * c.b, c.c(c.a, c.b));
var compiler = new CompiledExpression { StringToParse = "a + b - c(a * b, c(a, b))" };
var f = compiler.ScopeCompile<DynamicContainer>();
var result = f(c);
Assert.AreEqual(actual, result);
}


[TestMethod]
public void DynamicsUnboxingTest()
Expand Down

0 comments on commit 39dcf92

Please sign in to comment.