Skip to content

Commit

Permalink
Changed the BinderHelper to detect IDictionary inputs and return them…
Browse files Browse the repository at this point in the history
… unmodified.
  • Loading branch information
kppullin committed Oct 13, 2011
1 parent 6bdb3d1 commit 252147b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Simple.Data.UnitTest/BinderHelperTest.cs
Expand Up @@ -26,6 +26,15 @@ public void ArgumentsToDictionaryShouldApplyOrdinalNamesToFirstArguments()
var actual = binder.ArgumentsToDictionary(new object[] { 1, 2 });
Assert.AreEqual("_0", actual.First().Key);
}

[Test]
public void ArgumentsToDictionaryShouldReturnInputParameterWhenInputParameterIsDictionary()
{
var binder = new TestInvokeMemberBinder("Test", false, new CallInfo(1, "Foo"));
var input = new Dictionary<string, object> { { "Test1", 1 }, { "Test2", 2 } };
var actual = binder.ArgumentsToDictionary(new object[] { input });
Assert.AreEqual(input["Test2"], actual["Test2"]);
}
}

class TestInvokeMemberBinder : InvokeMemberBinder
Expand Down
6 changes: 5 additions & 1 deletion Simple.Data/BinderHelper.cs
Expand Up @@ -21,7 +21,11 @@ static class BinderHelper

public static IDictionary<string, object> ArgumentsToDictionary(this InvokeMemberBinder binder, IEnumerable<object> args)
{
return args.Reverse()
var argsArray = args.ToArray();
if (argsArray.Length == 1 && argsArray[0] is IDictionary<string, object>)
return (IDictionary<string, object>)argsArray[0];

return argsArray.Reverse()
.Zip(binder.CallInfo.ArgumentNames.Reverse().ExtendInfinite(), (v, k) => new KeyValuePair<string, object>(k, v))
.Reverse()
.Select((kvp, i) => kvp.Key == null ? new KeyValuePair<string, object>("_" + i.ToString(), kvp.Value) : kvp)
Expand Down

0 comments on commit 252147b

Please sign in to comment.