diff --git a/ExpressionEvaluator/Parser/ExpressionHelper.cs b/ExpressionEvaluator/Parser/ExpressionHelper.cs index 216e326..8269fef 100644 --- a/ExpressionEvaluator/Parser/ExpressionHelper.cs +++ b/ExpressionEvaluator/Parser/ExpressionHelper.cs @@ -269,6 +269,10 @@ public static void LowerBoundInference(Type U, Type V, Dictionary 0); + } public static Expression GetProperty(Expression le, string membername) { @@ -291,7 +295,7 @@ public static Expression GetProperty(Expression le, string membername) type = le.Type; instance = le; - isDynamic = (le.NodeType == ExpressionType.Dynamic) || type.IsDynamic(); + isDynamic = IsDynamic(le); if (!isDynamic) { diff --git a/UnitTests/DynamicTests.cs b/UnitTests/DynamicTests.cs index f0882ac..055708c 100644 --- a/UnitTests/DynamicTests.cs +++ b/UnitTests/DynamicTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Dynamic; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -98,5 +99,42 @@ public void DynamicValue() ret = cc.Eval(); Assert.AreEqual(true, ret); } + + [TestMethod] + public void DynamicMethodReturnType() + { + var typeRegistry = new TypeRegistry(); + dynamic obj = new Entity { Name = "MyName" }; + typeRegistry.RegisterSymbol("obj", obj); + typeRegistry.RegisterSymbol("entity", new EntityLoader()); + + var entity = new EntityLoader(); + Console.WriteLine("Expected: " + entity.GetParent(obj).Name); + ValidateExpression(typeRegistry, "entity.GetParent(obj).Name"); + } + + private static void ValidateExpression(TypeRegistry typeRegistry, string expression) + { + var compiler = new CompiledExpression { TypeRegistry = typeRegistry, StringToParse = expression }; + compiler.Compile(); + var result = compiler.Eval(); + Console.WriteLine(expression + " :: " + result); + } + } + + public class Entity + { + public string Name { get; set; } + } + + public class EntityLoader + { + public dynamic GetParent(dynamic entity) + { + return new Entity { Name = "Parent of " + entity.Name }; + } + } + + } \ No newline at end of file