Skip to content

Commit 9c1c3e1

Browse files
author
Sébastien Geiser
committed
conflict resolution
2 parents f207474 + 67dddbc commit 9c1c3e1

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,15 +1402,29 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingEvaluation
14021402

14031403
#region On the fly pre events cancel
14041404

1405-
evaluator = new ExpressionEvaluator();
1405+
evaluator = new ExpressionEvaluator(new Dictionary<string, object>
1406+
{
1407+
{ "P1var", "P1" },
1408+
{ "myObj", new ClassForTest1() },
1409+
});
14061410

14071411
evaluator.PreEvaluateVariable += (sender, e) =>
14081412
{
14091413
if (e.Name.StartsWith("P"))
14101414
e.CancelEvaluation = true;
14111415
};
14121416

1417+
evaluator.PreEvaluateFunction += (sender, e) =>
1418+
{
1419+
if (e.Name.StartsWith("A"))
1420+
e.CancelEvaluation = true;
1421+
};
1422+
14131423
yield return new TestCaseData(evaluator, "Pi", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Var");
1424+
yield return new TestCaseData(evaluator, "P1var", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Var");
1425+
yield return new TestCaseData(evaluator, "myObj.PropertyThatWillFailed", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Var");
1426+
yield return new TestCaseData(evaluator, "myObj.Add3To(5)", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Func");
1427+
yield return new TestCaseData(evaluator, "Abs(-5)", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Func");
14141428

14151429
#endregion
14161430
}
@@ -1565,14 +1579,20 @@ public static IEnumerable<TestCaseData> TestCasesEvaluateWithSpecificEvaluator
15651579

15661580
#region Onthefly events (Pre events and/or Generics and/or Static)
15671581

1568-
ExpressionEvaluator evaluatorOnTheFlies = new ExpressionEvaluator();
1582+
ExpressionEvaluator evaluatorOnTheFlyGenericTypes = new ExpressionEvaluator(new Dictionary<string, object>
1583+
{
1584+
{ "myvar1", 10 },
1585+
{ "myvar2", 3 },
1586+
});
15691587

15701588
evaluatorOnTheFlies.Namespaces.Add("CodingSeb.ExpressionEvaluator.Tests");
15711589

15721590
void VariableEval(object sender, VariableEvaluationEventArg e)
15731591
{
1574-
if(e.Name.Equals("GetSpecifiedGenericTypesVar"))
1592+
if (e.Name.Equals("GetSpecifiedGenericTypesVar"))
15751593
e.Value = e.EvaluateGenericTypes();
1594+
else if (e.Name.Equals("myvar2"))
1595+
e.Value = 50;
15761596
else if (e.This is ClassOrTypeName classOrTypeName && classOrTypeName.Type == typeof(ClassForTest1) && e.Name.Equals("OnTheFlyStaticVar"))
15771597
{
15781598
e.Value = 10;
@@ -1665,6 +1685,16 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
16651685
.SetCategory("On the fly var")
16661686
.SetCategory("Static Onthefly");
16671687

1688+
yield return new TestCaseData(evaluatorOnTheFlyGenericTypes
1689+
, "myvar1")
1690+
.Returns(5)
1691+
.SetCategory("var evaluation priority");
1692+
1693+
yield return new TestCaseData(evaluatorOnTheFlyGenericTypes
1694+
, "myvar2")
1695+
.Returns(3)
1696+
.SetCategory("var evaluation priority");
1697+
16681698
yield return new TestCaseData(evaluatorOnTheFlies
16691699
, "ClassForTest1.OnTheFlyStaticPreFunc()")
16701700
.Returns(5)
@@ -1678,6 +1708,15 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
16781708
.SetCategory("Static Onthefly");
16791709

16801710
#endregion
1711+
1712+
#region bug resolution
1713+
1714+
yield return new TestCaseData(new ExpressionEvaluator()
1715+
, "(new List<Regex>()).GetType()")
1716+
.Returns(typeof(List<Regex>))
1717+
.SetCategory("Bug resolution");
1718+
1719+
#endregion
16811720
}
16821721
}
16831722

CodingSeb.ExpressionEvaluator.Tests/TestsUtils/ClassForTest1.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class ClassForTest1
1212

1313
public static int StaticIntProperty { get; set; } = 67;
1414

15+
public int PropertyThatWillFailed { get; set; } = 1;
16+
1517
public int Add3To(int value)
1618
{
1719
return value + 3;

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************************************
22
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3-
Version : 1.3.7.1
3+
Version : 1.3.7.2
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
@@ -2120,7 +2120,6 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
21202120
stack.Push(varValueToPush);
21212121
}
21222122
else if ((Variables.TryGetValue(varFuncName, out object cusVarValueToPush) || varFuncMatch.Groups["assignationOperator"].Success)
2123-
&& !varFuncMatch.Groups["inObject"].Success
21242123
&& (cusVarValueToPush == null || !TypesToBlock.Contains(cusVarValueToPush.GetType())))
21252124
{
21262125
stack.Push(cusVarValueToPush);
@@ -3090,7 +3089,7 @@ private Type GetTypeByFriendlyName(string typeName, string genericTypes = "", bo
30903089
if (!genericTypes.Equals(string.Empty))
30913090
{
30923091
Type[] types = GetConcreteTypes(genericTypes);
3093-
formatedGenericTypes = $"`{types.Length}[{ string.Join(", ", types.Select(type => type.FullName))}]";
3092+
formatedGenericTypes = $"`{types.Length}[{ string.Join(", ", types.Select(type => "[" + type.AssemblyQualifiedName + "]"))}]";
30943093
}
30953094

30963095
result = Type.GetType(typeName + formatedGenericTypes, false, !OptionCaseSensitiveEvaluationActive);

0 commit comments

Comments
 (0)