Skip to content

Commit 4d5209f

Browse files
author
Sébastien Geiser
committed
Static on the flies OK
1 parent 3c68929 commit 4d5209f

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ void Evaluator_PreEvaluateFunction(object sender, FunctionPreEvaluationEventArg
16201620
// e.EvaluateGenericTypes() return a Type[]
16211621
e.Value = e.EvaluateGenericTypes()[0].Namespace;
16221622
}
1623-
else if (e.This is ClassOrTypeName classOrTypeName && classOrTypeName.Type == typeof(ClassForTest1) && e.Name.Equals("OnTheFlyStaticPreVar"))
1623+
else if (e.This is ClassOrTypeName classOrTypeName && classOrTypeName.Type == typeof(ClassForTest1) && e.Name.Equals("OnTheFlyStaticPreFunc"))
16241624
{
16251625
e.Value = 15;
16261626
}
@@ -1637,7 +1637,7 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
16371637
// e.EvaluateGenericTypes() return a Type[]
16381638
e.Value = e.EvaluateGenericTypes()[0].Assembly.GetName().Name;
16391639
}
1640-
else if (e.This is ClassOrTypeName classOrTypeName && classOrTypeName.Type == typeof(ClassForTest1) && e.Name.Equals("OnTheFlyStaticPreFunc"))
1640+
else if (e.This is ClassOrTypeName classOrTypeName && classOrTypeName.Type == typeof(ClassForTest1) && e.Name.Equals("OnTheFlyStaticPreVar"))
16411641
{
16421642
e.Value = 3;
16431643
}
@@ -1673,18 +1673,6 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
16731673
.SetCategory("On the fly var")
16741674
.SetCategory("GenericTypes");
16751675

1676-
yield return new TestCaseData(evaluatorOnTheFlies
1677-
, "ClassForTest1.OnTheFlyStaticFunc()")
1678-
.Returns(5)
1679-
.SetCategory("On the fly func")
1680-
.SetCategory("Static Onthefly");
1681-
1682-
yield return new TestCaseData(evaluatorOnTheFlies
1683-
, "ClassForTest1.OnTheFlyStaticVar")
1684-
.Returns(5)
1685-
.SetCategory("On the fly var")
1686-
.SetCategory("Static Onthefly");
1687-
16881676
yield return new TestCaseData(evaluatorOnTheFlies
16891677
, "myvar1")
16901678
.Returns(5)
@@ -1695,15 +1683,27 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
16951683
.Returns(3)
16961684
.SetCategory("var evaluation priority");
16971685

1686+
yield return new TestCaseData(evaluatorOnTheFlies
1687+
, "ClassForTest1.OnTheFlyStaticFunc()")
1688+
.Returns(8)
1689+
.SetCategory("On the fly func")
1690+
.SetCategory("Static Onthefly");
1691+
1692+
yield return new TestCaseData(evaluatorOnTheFlies
1693+
, "ClassForTest1.OnTheFlyStaticVar")
1694+
.Returns(10)
1695+
.SetCategory("On the fly var")
1696+
.SetCategory("Static Onthefly");
1697+
16981698
yield return new TestCaseData(evaluatorOnTheFlies
16991699
, "ClassForTest1.OnTheFlyStaticPreFunc()")
1700-
.Returns(5)
1700+
.Returns(15)
17011701
.SetCategory("On the fly func")
17021702
.SetCategory("Static Onthefly");
17031703

17041704
yield return new TestCaseData(evaluatorOnTheFlies
17051705
, "ClassForTest1.OnTheFlyStaticPreVar")
1706-
.Returns(5)
1706+
.Returns(3)
17071707
.SetCategory("On the fly var")
17081708
.SetCategory("Static Onthefly");
17091709

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
17621762
else
17631763
{
17641764
object obj = stack.Pop();
1765+
object keepObj = obj;
17651766
Type objType = null;
17661767
ValueTypeNestingTrace valueTypeNestingTrace = null;
17671768

@@ -1848,7 +1849,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
18481849
}
18491850
else
18501851
{
1851-
FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg(varFuncName, Evaluate, funcArgs, this, obj, genericsTypes, GetConcreteTypes);
1852+
FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg(varFuncName, Evaluate, funcArgs, this, obj ?? keepObj, genericsTypes, GetConcreteTypes);
18521853

18531854
EvaluateFunction?.Invoke(this, functionEvaluationEventArg);
18541855

@@ -1928,6 +1929,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
19281929
throw new ExpressionEvaluatorSyntaxErrorException($"[{varFuncMatch.Value}] must follow an object.");
19291930

19301931
object obj = stack.Pop();
1932+
object keepObj = obj;
19311933
Type objType = null;
19321934
ValueTypeNestingTrace valueTypeNestingTrace = null;
19331935

@@ -1989,7 +1991,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
19891991

19901992
if (member == null && pushVarValue)
19911993
{
1992-
VariableEvaluationEventArg variableEvaluationEventArg = new VariableEvaluationEventArg(varFuncName, this, obj, genericsTypes, GetConcreteTypes);
1994+
VariableEvaluationEventArg variableEvaluationEventArg = new VariableEvaluationEventArg(varFuncName, this, obj ?? keepObj, genericsTypes, GetConcreteTypes);
19931995

19941996
EvaluateVariable?.Invoke(this, variableEvaluationEventArg);
19951997

0 commit comments

Comments
 (0)