33
44using System . Linq ;
55using System . Linq . Expressions ;
6+ using System . Reflection ;
67using Antlr4 . Runtime . Misc ;
78using Simpleflow . Exceptions ;
89using Simpleflow . Parser ;
@@ -51,7 +52,7 @@ var indexProperty
5152 . GetProperties ( )
5253 . SingleOrDefault ( p => p . GetIndexParameters ( ) . Length == 1 &&
5354 p . GetIndexParameters ( ) [ 0 ] . ParameterType == indexExpression . Type ) ;
54-
55+
5556 return Expression . MakeIndex ( objectExp , indexProperty , new [ ] { indexExpression } ) ;
5657 }
5758
@@ -68,16 +69,31 @@ private Expression GetFinalPropertyValue(Expression propExp, SimpleflowParser.Id
6869 var propName = property . Identifier ( ) . GetText ( ) ;
6970 var prop = GetPropertyInfo ( propExp . Type , propName ) ;
7071
72+ // Support property or field
73+
74+ FieldInfo field = null ;
7175 if ( prop == null )
7276 {
73- throw new InvalidPropertyException ( $ "Invalid property '{ propName } '") ;
77+ field = GetFieldInfo ( propExp . Type , propName ) ;
78+
79+ if ( field == null )
80+ {
81+ throw new InvalidPropertyException ( $ "Invalid property or field '{ propName } '") ;
82+ }
7483 }
7584
7685 // Get indexed object
7786 propExp = GetIndexObjectExpIfDefined ( propExp , property . index ( ) ) ;
7887
7988 // Get property of indexed object
80- propExp = Expression . Property ( propExp , prop ) ;
89+ if ( prop != null )
90+ {
91+ propExp = Expression . Property ( propExp , prop ) ;
92+ }
93+ else
94+ {
95+ propExp = Expression . Field ( propExp , field ) ;
96+ }
8197 }
8298 return propExp ;
8399 }
0 commit comments