Skip to content

Commit f3f070d

Browse files
committed
Merge branch 'master' into dev
2 parents 7c15109 + b20c910 commit f3f070d

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************************************
22
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3-
Version : 1.4.18.0
3+
Version : 1.4.18.1
44
(if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable)
55
66
Author : Coding Seb
@@ -18,6 +18,7 @@
1818
using System.Runtime.InteropServices;
1919
using System.Text;
2020
using System.Text.RegularExpressions;
21+
using System.Runtime.CompilerServices;
2122

2223
namespace CodingSeb.ExpressionEvaluator
2324
{
@@ -836,6 +837,13 @@ public bool OptionNewFunctionEvaluationActive
836837
/// </summary>
837838
public bool OptionAllowNonPublicMembersAccess { get; set; }
838839

840+
/// <summary>
841+
/// If <c>true</c> On unsuccessful call to an extension method, all defined overloads of that method are detected to resolve whether method is defined and called with wrong arguments or method is not defined.
842+
/// If <c>false</c> Unsucessful call to an extension method will always result in "Method {name} is not defined on type {type}"
843+
/// Default : true
844+
/// </summary>
845+
public bool OptionDetectExtensionMethodsOverloadsOnExtensionMethodNotFound { get; set; } = true;
846+
839847
#endregion
840848

841849
#region Reflection flags
@@ -1954,6 +1962,33 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
19541962
}
19551963
else
19561964
{
1965+
if (OptionDetectExtensionMethodsOverloadsOnExtensionMethodNotFound)
1966+
{
1967+
IEnumerable<MethodInfo> query = from type in StaticTypesForExtensionsMethods
1968+
where
1969+
!type.IsGenericType &&
1970+
type.IsSealed &&
1971+
!type.IsNested
1972+
from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
1973+
where method.IsDefined(typeof(ExtensionAttribute), false)
1974+
where method.GetParameters()[0].ParameterType == objType // static extMethod(this outType, ...)
1975+
select method;
1976+
1977+
if (query.Any())
1978+
{
1979+
string fnArgsPrint = string.Join(",", funcArgs);
1980+
string fnOverloadsPrint = "";
1981+
1982+
foreach (MethodInfo mi in query)
1983+
{
1984+
ParameterInfo[] parInfo = mi.GetParameters();
1985+
fnOverloadsPrint += string.Join(",", parInfo.Select(x => x.ParameterType.FullName ?? x.ParameterType.Name)) + "\n";
1986+
}
1987+
1988+
throw new ExpressionEvaluatorSyntaxErrorException($"[{objType}] extension method \"{varFuncName}\" has no overload for arguments: {fnArgsPrint}. Candidates: {fnOverloadsPrint}");
1989+
}
1990+
}
1991+
19571992
throw new ExpressionEvaluatorSyntaxErrorException($"[{objType}] object has no Method named \"{varFuncName}\".");
19581993
}
19591994
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ It is largely based on and inspired by the following resources [this post on st
3636
## And with [ScriptEvaluate](https://github.com/codingseb/ExpressionEvaluator/wiki/Getting-Started#small-scripts) method
3737
* Small C# like script evaluation (Multi expressions separated by ; )
3838
* Some conditional and loop blocks [keywords](https://github.com/codingseb/ExpressionEvaluator/wiki/Operators-and-Keywords#scripts-keywords) (if, while, for, foreach ...)
39-
* Multi-line (multi expression) Lambda expressions.
39+
* Multi-line (multi expression) Lambda expressions. (Can be use as method [See #72 Declare methods in scripts](https://github.com/codingseb/ExpressionEvaluator/issues/72))
4040

4141
## Resources
4242
* [Getting Started](https://github.com/codingseb/ExpressionEvaluator/wiki/Getting-Started)
@@ -67,3 +67,10 @@ The biggest difference of ExpressionEvaluator is that everything is evaluated on
6767
So it can be slower in some cases (sometimes not) but it also avoid a lot of memory leaks.
6868
It already allow to evaluate some small scripts.
6969
If you don't want an another .dll file in your project, you only need to copy one [C# file](./CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs) in your project. And it's [MIT licence](./LICENSE.md)
70+
71+
### Donate
72+
Expression Evaluator is free and will always be.
73+
But if you want to say thanks for this lib with a donation or small sponsoring here you can :
74+
[Donate](https://www.paypal.com/donate?hosted_button_id=7K467U3H4NVJG)
75+
76+
Thank you anyway for using ExpressionEvaluator

0 commit comments

Comments
 (0)