Skip to content

Commit e093f1c

Browse files
fix: Fixed ValueContainer.cs and AccessValueRule.cs to support the new structure
1 parent b24411e commit e093f1c

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

ExpressionEngine/Rules/AccessValueRule.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public ValueContainer Evaluate()
2525

2626
if (currentValue.Type() == ValueContainer.ValueType.Array)
2727
{
28-
var asArray = currentValue.GetValue<ValueContainer[]>();
2928
if (index.Type() != ValueContainer.ValueType.Integer)
3029
{
3130
throw InvalidTemplateException.BuildInvalidTemplateExceptionArray(
@@ -34,47 +33,48 @@ public ValueContainer Evaluate()
3433
index.GetValue<string>());
3534
}
3635

37-
var i = index.GetValue<int>();
38-
if (i > asArray.Length)
36+
try
37+
{
38+
return currentValue[index.GetValue<int>()];
39+
}
40+
catch (IndexOutOfRangeException)
3941
{
4042
if (nullConditional)
4143
{
4244
return new ValueContainer();
4345
}
44-
throw new IndexOutOfRangeException();
45-
}
4646

47-
currentValue = asArray[i];
47+
throw;
48+
}
4849
}
4950

50-
else if (currentValue.Type() == ValueContainer.ValueType.Object)
51+
if (currentValue.Type() == ValueContainer.ValueType.Object)
5152
{
52-
var asObject = currentValue.GetValue<Dictionary<string, ValueContainer>>();
53-
var key = index.GetValue<string>();
54-
55-
if (asObject.ContainsKey(key))
53+
try
5654
{
57-
return asObject[key];
55+
return currentValue[index.GetValue<string>()];
5856
}
59-
57+
catch (KeyNotFoundException)
58+
{
6059
if (nullConditional)
6160
{
6261
return new ValueContainer();
6362
}
6463

65-
throw InvalidTemplateException.BuildInvalidTemplateExceptionObject(
66-
(_func as ExpressionRule)?.FunctionName,
67-
_func.PrettyPrint() + _indexRule.PrettyPrint(),
68-
index.GetValue<string>(),
69-
asObject.Keys.ToArray());
64+
throw InvalidTemplateException.BuildInvalidTemplateExceptionObject(
65+
(_func as ExpressionRule)?.FunctionName,
66+
_func.PrettyPrint() + _indexRule.PrettyPrint(),
67+
index.GetValue<string>(),
68+
currentValue.GetValue<Dictionary<string, ValueContainer>>().Keys.ToArray());
69+
}
7070
}
7171

7272
return currentValue;
7373
}
7474

7575
public string PrettyPrint()
7676
{
77-
throw new NotImplementedException();
77+
return $"{_func.PrettyPrint()}{_indexRule.PrettyPrint()}";
7878
}
7979
}
8080
}

ExpressionEngine/ValueContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public ValueContainer this[int i]
156156
throw new InvalidOperationException("Index operations can only be performed on arrays.");
157157
}
158158

159-
return ((List<ValueContainer>) _value)[i];
159+
return _value[i];
160160
}
161161
set
162162
{

0 commit comments

Comments
 (0)