Skip to content

Commit 976e070

Browse files
committed
Correction of bug #67 When a ExpandoObject has a null property
1 parent 55128e9 commit 976e070

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,12 +1153,32 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
11531153
yield return new TestCaseData("string.IsNullOrEmpty(nullVar) || nullVar.StartsWith(\"ABC\") == false", onInstanceVariables, true).SetCategory("Instance Property,Or Conditional").Returns(true);
11541154
yield return new TestCaseData("!string.IsNullOrEmpty(nullVar) && nullVar.Length < 2", onInstanceVariables, true).SetCategory("Instance Property,And Conditional").Returns(false);
11551155
yield return new TestCaseData("string.IsNullOrEmpty(nullVar) || nullVar.Length < 2", onInstanceVariables, true).SetCategory("Instance Property,Or Conditional").Returns(true);
1156-
yield return new TestCaseData("true || 1/0 == 0", onInstanceVariables, true).SetCategory("Instance Property,Or Conditional").Returns(true);
1156+
yield return new TestCaseData("true || 1/0 == 0", onInstanceVariables, true).SetCategory("Instance Property,Or Conditional").Returns(true);
11571157
yield return new TestCaseData("false && true || true", onInstanceVariables, true).SetCategory("Instance Property,Or Conditional,And Conditional,Precedence check").Returns(true);
11581158
yield return new TestCaseData("true || true && false", onInstanceVariables, true).SetCategory("Instance Property,Or Conditional,And Conditional,Precedence check").Returns(true);
11591159
yield return new TestCaseData("false && nullVar.What ? nullVar.Text : \"Hello\"", onInstanceVariables, true).SetCategory("Instance Property,Ternary operator, And Conditional").Returns("Hello");
11601160
yield return new TestCaseData("false && (false && nullVar.What ? nullVar.boolValue : true) ? nullVar.Text : \"Hello\"", onInstanceVariables, true).SetCategory("Instance Property,Ternary operator, And Conditional").Returns("Hello");
11611161

1162+
#endregion
1163+
1164+
#region ExpandoObject
1165+
1166+
dynamic MyDynamic = new System.Dynamic.ExpandoObject();
1167+
MyDynamic.NullValue = null;
1168+
MyDynamic.Number = 11;
1169+
1170+
Dictionary<string, object> ExpandoObjectVariables = new Dictionary<string, object>()
1171+
{
1172+
{ "expObj", MyDynamic },
1173+
};
1174+
1175+
yield return new TestCaseData("expObj.Number", ExpandoObjectVariables, true).SetCategory("ExpandoObject").SetCategory("Instance Property").Returns(11);
1176+
1177+
#region bug #67
1178+
yield return new TestCaseData("expObj.NullValue", ExpandoObjectVariables, true).SetCategory("ExpandoObject").SetCategory("Instance Property").Returns(null);
1179+
yield return new TestCaseData("expObj.NullValue ?? \"A\"", ExpandoObjectVariables, true).SetCategory("ExpandoObject").SetCategory("Instance Property").Returns("A");
1180+
#endregion
1181+
11621182

11631183
#endregion
11641184

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
21172117
}
21182118
}
21192119

2120-
if (varValue == null && pushVarValue)
2120+
if (!isDynamic && varValue == null && pushVarValue)
21212121
{
21222122
varValue = ((dynamic)member).GetValue(obj);
21232123

0 commit comments

Comments
 (0)