@@ -1719,6 +1719,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
1719
1719
{
1720
1720
object obj = stack . Pop ( ) ;
1721
1721
Type objType = null ;
1722
+ ValueTypeNestingTrace valueTypeNestingTrace = null ;
1722
1723
1723
1724
if ( obj != null && TypesToBlock . Contains ( obj . GetType ( ) ) )
1724
1725
throw new ExpressionEvaluatorSecurityException ( $ "{ obj . GetType ( ) . FullName } type is blocked") ;
@@ -1746,7 +1747,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
1746
1747
else
1747
1748
{
1748
1749
List < object > oArgs = funcArgs . ConvertAll ( arg => Evaluate ( arg ) ) ;
1749
- BindingFlags flag = DetermineInstanceOrStatic ( ref objType , ref obj ) ;
1750
+ BindingFlags flag = DetermineInstanceOrStatic ( ref objType , ref obj , ref valueTypeNestingTrace ) ;
1750
1751
1751
1752
if ( ! OptionStaticMethodsCallActive && ( flag & BindingFlags . Static ) != 0 )
1752
1753
throw new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType } ] object has no Method named \" { varFuncName } \" .") ;
@@ -1923,6 +1924,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
1923
1924
1924
1925
object obj = stack . Pop ( ) ;
1925
1926
Type objType = null ;
1927
+ ValueTypeNestingTrace valueTypeNestingTrace = null ;
1926
1928
1927
1929
if ( obj != null && TypesToBlock . Contains ( obj . GetType ( ) ) )
1928
1930
throw new ExpressionEvaluatorSecurityException ( $ "{ obj . GetType ( ) . FullName } type is blocked") ;
@@ -1949,7 +1951,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
1949
1951
}
1950
1952
else
1951
1953
{
1952
- BindingFlags flag = DetermineInstanceOrStatic ( ref objType , ref obj ) ;
1954
+ BindingFlags flag = DetermineInstanceOrStatic ( ref objType , ref obj , ref valueTypeNestingTrace ) ;
1953
1955
1954
1956
if ( ! OptionStaticProperiesGetActive && ( flag & BindingFlags . Static ) != 0 )
1955
1957
throw new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType } ] object has no public Property or Field named \" { varFuncName } \" .") ;
@@ -1978,10 +1980,22 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
1978
1980
else
1979
1981
{
1980
1982
varValue = ( ( dynamic ) member ) . GetValue ( obj ) ;
1983
+
1984
+ if ( varValue is ValueType valueType && member is FieldInfo fieldInfo )
1985
+ {
1986
+ varValue = valueTypeNestingTrace = new ValueTypeNestingTrace
1987
+ {
1988
+ Container = valueTypeNestingTrace ?? obj ,
1989
+ Field = fieldInfo ,
1990
+ Value = valueType
1991
+ } ;
1992
+ }
1981
1993
}
1982
1994
1983
1995
if ( pushVarValue )
1996
+ {
1984
1997
stack . Push ( varValue ) ;
1998
+ }
1985
1999
1986
2000
if ( OptionPropertyOrFieldSetActive )
1987
2001
{
@@ -2027,16 +2041,15 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
2027
2041
}
2028
2042
else
2029
2043
{
2030
- //if (objType.IsValueType && member is FieldInfo fieldInfo)
2031
- //{
2032
- // Action<object, object> setter = GetDelegateForStruct(objType, fieldInfo);
2033
- // ValueType valueType = obj as ValueType;
2034
- // setter(valueType, varValue);
2035
- //}
2036
- //else
2037
- //{
2044
+ if ( valueTypeNestingTrace != null )
2045
+ {
2046
+ valueTypeNestingTrace . Value = varValue ;
2047
+ valueTypeNestingTrace . AssignValue ( ) ;
2048
+ }
2049
+ else
2050
+ {
2038
2051
( ( dynamic ) member ) . SetValue ( obj , varValue ) ;
2039
- // }
2052
+ }
2040
2053
}
2041
2054
}
2042
2055
}
@@ -2500,7 +2513,9 @@ private bool EvaluateString(string expr, string s, string restOfExpression, Stac
2500
2513
2501
2514
private object ProcessStack ( Stack < object > stack )
2502
2515
{
2503
- List < object > list = stack . ToList ( ) ;
2516
+ List < object > list = stack
2517
+ . Select ( e => e is ValueTypeNestingTrace valueTypeNestingTrace ? valueTypeNestingTrace . Value : e )
2518
+ . ToList ( ) ;
2504
2519
2505
2520
operatorsEvaluations . ForEach ( ( Dictionary < ExpressionOperator , Func < dynamic , dynamic , object > > operatorEvalutationsDict ) =>
2506
2521
{
@@ -2759,8 +2774,15 @@ private Type[] GetConcreteTypes(string genericsTypes)
2759
2774
. ToArray ( ) ;
2760
2775
}
2761
2776
2762
- private BindingFlags DetermineInstanceOrStatic ( ref Type objType , ref object obj )
2777
+ private BindingFlags DetermineInstanceOrStatic ( ref Type objType , ref object obj , ref ValueTypeNestingTrace valueTypeNestingTrace )
2763
2778
{
2779
+ valueTypeNestingTrace = obj as ValueTypeNestingTrace ;
2780
+
2781
+ if ( valueTypeNestingTrace != null )
2782
+ {
2783
+ obj = valueTypeNestingTrace . Value ;
2784
+ }
2785
+
2764
2786
if ( obj is ClassOrTypeName classOrTypeName )
2765
2787
{
2766
2788
objType = classOrTypeName . Type ;
@@ -3095,6 +3117,29 @@ private class ClassOrTypeName
3095
3117
public Type Type { get ; set ; }
3096
3118
}
3097
3119
3120
+ private class ValueTypeNestingTrace
3121
+ {
3122
+ public object Container { get ; set ; }
3123
+
3124
+ public FieldInfo Field { get ; set ; }
3125
+
3126
+ public object Value { get ; set ; }
3127
+
3128
+ public void AssignValue ( )
3129
+ {
3130
+ if ( Container is ValueTypeNestingTrace valueTypeNestingTrace )
3131
+ {
3132
+ Field . SetValue ( valueTypeNestingTrace . Value , Value ) ;
3133
+ valueTypeNestingTrace . AssignValue ( ) ;
3134
+ }
3135
+ else
3136
+ {
3137
+ Field . SetValue ( Container , Value ) ;
3138
+ }
3139
+
3140
+ }
3141
+ }
3142
+
3098
3143
private class DelegateEncaps
3099
3144
{
3100
3145
private readonly InternalDelegate lambda ;
0 commit comments