afscrome / IronVelocity

A wrapper around NVelocity (a port of Apache Velocity) using the DLR to provide higher performance template execution.
MIT License
6 stars 1 forks source link

VelocityInvokeMemberBinder and ExpandoObject #52

Closed afscrome closed 8 years ago

afscrome commented 8 years ago

VelocityInvokeMemberBinder does not work with ExpandoObject. This is because ExpandoObject works by a GetMember operation, followed by an Invoke on the retrieved member. This fails because FallbackInvoke is not implemented in VelocityInvokeMemberBinder .

In FallbackInvoke, the target should be a delegate (Func, Action, custom deletage), which should be invoked with the given arguments (provided they're compatible)

public void ShouldInvokeMemberOnDynamicObject()
{
    dynamic input = new ExpandoObject();
    input.Double = new Func<int,int>(x => x * 2);

    var result = test(input, "Double", 123);
    Assert.That(result, Is.EqualTo(246));
}

Related to #45.