Skip to content

Commit

Permalink
Ignore multiple registration of the same delegate with the same name. (
Browse files Browse the repository at this point in the history
  • Loading branch information
metoule authored Jul 2, 2021
1 parent 4aabda0 commit 12bb256
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/DynamicExpresso.Core/Identifier.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

Expand Down Expand Up @@ -56,7 +56,9 @@ internal MethodGroupExpression(Delegate overload)

internal void AddOverload(Delegate overload)
{
_overloads.Add(overload);
// don't register the same overload twice
if (_overloads.IndexOf(overload) == -1)
_overloads.Add(overload);
}
}
}
13 changes: 12 additions & 1 deletion test/DynamicExpresso.UnitTest/VariablesTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using NUnit.Framework;
using System.Linq.Expressions;
using DynamicExpresso.Exceptions;
Expand Down Expand Up @@ -140,6 +140,17 @@ public void Keywords_with_delegate()
Assert.AreEqual(9.0, target.Eval("pow(3, 2)"));
}

[Test]
public void Keywords_with_same_overload_twice()
{
Func<double, double, double> pow = (x, y) => Math.Pow(x, y);
var target = new Interpreter()
.SetFunction("pow", pow)
.SetFunction("pow", pow);

Assert.AreEqual(9.0, target.Eval("pow(3, 2)"));
}

[Test]
public void Keywords_with_invalid_delegate_call()
{
Expand Down

0 comments on commit 12bb256

Please sign in to comment.