Skip to content

Commit af2a2a2

Browse files
author
Sébastien Geiser
committed
modify test to test also simple fields.
+ Fields Management in context
1 parent fe321d1 commit af2a2a2

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,12 +1762,12 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
17621762

17631763
evaluatorWithPersonContext.Context = new Person1()
17641764
{
1765-
Name = "John",
1765+
name = "John",
17661766
LastName = "Smith"
17671767
};
17681768

17691769
yield return new TestCaseData(evaluatorWithPersonContext
1770-
, "Name + \" \" + LastName"
1770+
, "name + \" \" + LastName"
17711771
, null)
17721772
.Returns("John Smith")
17731773
.SetCategory("Context object");

CodingSeb.ExpressionEvaluator.Tests/TestsUtils/Person1.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
{
33
public class Person1
44
{
5-
public string Name { get; set; }
5+
public string name;
66
public string LastName { get; set; }
7+
78
public int APersonMethod()
89
{
910
return 10;

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,9 +1943,13 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
19431943
}
19441944
else
19451945
{
1946-
if (inObject || Context?.GetType()
1946+
if (inObject
1947+
|| Context?.GetType()
19471948
.GetProperties()
1948-
.Any(propInfo => propInfo.Name.Equals(varFuncName, StringComparisonForCasing)) == true)
1949+
.Any(propInfo => propInfo.Name.Equals(varFuncName, StringComparisonForCasing)) == true
1950+
|| Context?.GetType()
1951+
.GetFields()
1952+
.Any(fieldInfo => fieldInfo.Name.Equals(varFuncName, StringComparisonForCasing)) == true)
19491953
{
19501954
if (inObject && (stack.Count == 0 || stack.Peek() is ExpressionOperator))
19511955
throw new ExpressionEvaluatorSyntaxErrorException($"[{varFuncMatch.Value}] must follow an object.");

0 commit comments

Comments
 (0)