@@ -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}
0 commit comments