@@ -36,7 +36,7 @@ public partial class ExpressionEvaluator
36
36
protected static readonly Regex varOrFunctionRegEx = new Regex ( $@ "^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var)\s+|(?<dynamicKeyword>dynamic)\s+|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[{ diactiticsKeywordsRegexPattern } ](?>[{ diactiticsKeywordsRegexPattern } 0-9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![{ diactiticsKeywordsRegexPattern } 0-9]))|((?<isgeneric>[<](?>([{ diactiticsKeywordsRegexPattern } ](?>[{ diactiticsKeywordsRegexPattern } 0-9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))", RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
37
37
38
38
protected const string numberRegexOrigPattern = @"^(?<sign>[+-])?([0-9][0-9_{1}]*[0-9]|\d)(?<hasdecimal>{0}?([0-9][0-9_]*[0-9]|\d)(e[+-]?([0-9][0-9_]*[0-9]|\d))?)?(?<type>ul|[fdulm])?" ;
39
- protected string numberRegexPattern = null ;
39
+ protected string numberRegexPattern ;
40
40
41
41
protected static readonly Regex otherBasesNumberRegex = new Regex ( "^(?<sign>[+-])?(?<value>0(?<type>x)([0-9a-f][0-9a-f_]*[0-9a-f]|[0-9a-f])|0(?<type>b)([01][01_]*[01]|[01]))" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
42
42
protected static readonly Regex stringBeginningRegex = new Regex ( "^(?<interpolated>[$])?(?<escaped>[@])?[\" ]" , RegexOptions . Compiled ) ;
@@ -773,7 +773,7 @@ public bool OptionNewFunctionEvaluationActive
773
773
/// If <c>ThrowSyntaxException</c> a exception is throw if no return keyword is met.
774
774
/// By default : ReturnAutomaticallyLastEvaluatedExpression;
775
775
/// </summary>
776
- public OptionOnNoReturnKeywordFoundInScriptAction OptionOnNoReturnKeywordFoundInScriptAction { get ; set ; } = OptionOnNoReturnKeywordFoundInScriptAction . ReturnAutomaticallyLastEvaluatedExpression ;
776
+ public OptionOnNoReturnKeywordFoundInScriptAction OptionOnNoReturnKeywordFoundInScriptAction { get ; set ; }
777
777
778
778
/// <summary>
779
779
/// If <c>true</c> ScriptEvaluate need to have a semicolon [;] after each expression.
@@ -939,7 +939,7 @@ protected virtual void Init()
939
939
/// <typeparam name="T">The type in which to cast the result of the expression</typeparam>
940
940
/// <param name="script">the script to evaluate</param>
941
941
/// <returns>The result of the last evaluated expression</returns>
942
- public T ScriptEvaluate < T > ( string script )
942
+ public virtual T ScriptEvaluate < T > ( string script )
943
943
{
944
944
return ( T ) ScriptEvaluate ( script ) ;
945
945
}
@@ -1546,8 +1546,8 @@ protected virtual bool EvaluateNumber(string expression, Stack<object> stack, re
1546
1546
}
1547
1547
else if ( numberMatch . Success
1548
1548
&& ( ! numberMatch . Groups [ "sign" ] . Success
1549
- || stack . Count == 0
1550
- || stack . Peek ( ) is ExpressionOperator ) )
1549
+ || stack . Count == 0
1550
+ || stack . Peek ( ) is ExpressionOperator ) )
1551
1551
{
1552
1552
i += numberMatch . Length ;
1553
1553
i -- ;
@@ -1562,16 +1562,13 @@ protected virtual bool EvaluateNumber(string expression, Stack<object> stack, re
1562
1562
stack . Push ( parseFunc ( numberNoType , CultureInfoForNumberParsing ) ) ;
1563
1563
}
1564
1564
}
1565
+ else if ( OptionForceIntegerNumbersEvaluationsAsDoubleByDefault || numberMatch . Groups [ "hasdecimal" ] . Success )
1566
+ {
1567
+ stack . Push ( double . Parse ( numberMatch . Value . Replace ( "_" , "" ) , NumberStyles . Any , CultureInfoForNumberParsing ) ) ;
1568
+ }
1565
1569
else
1566
1570
{
1567
- if ( OptionForceIntegerNumbersEvaluationsAsDoubleByDefault || numberMatch . Groups [ "hasdecimal" ] . Success )
1568
- {
1569
- stack . Push ( double . Parse ( numberMatch . Value . Replace ( "_" , "" ) , NumberStyles . Any , CultureInfoForNumberParsing ) ) ;
1570
- }
1571
- else
1572
- {
1573
- stack . Push ( int . Parse ( numberMatch . Value . Replace ( "_" , "" ) , NumberStyles . Any , CultureInfoForNumberParsing ) ) ;
1574
- }
1571
+ stack . Push ( int . Parse ( numberMatch . Value . Replace ( "_" , "" ) , NumberStyles . Any , CultureInfoForNumberParsing ) ) ;
1575
1572
}
1576
1573
1577
1574
return true ;
@@ -2984,7 +2981,7 @@ protected virtual MethodInfo GetRealMethod(ref Type type, ref object obj, string
2984
2981
&& modifiedArgs [ a ] is InternalDelegate )
2985
2982
{
2986
2983
InternalDelegate led = modifiedArgs [ a ] as InternalDelegate ;
2987
- modifiedArgs [ a ] = new Converter < object , object > ( o => ( led ( new object [ ] { o } ) ) ) ;
2984
+ modifiedArgs [ a ] = new Converter < object , object > ( o => led ( new object [ ] { o } ) ) ;
2988
2985
}
2989
2986
else
2990
2987
{
@@ -3118,7 +3115,7 @@ protected virtual string GetScriptBetweenCurlyBrackets(string parentScript, ref
3118
3115
return currentScript ;
3119
3116
}
3120
3117
3121
- protected List < string > GetExpressionsBetweenParenthesesOrOtherImbricableBrackets ( string expression , ref int i , bool checkSeparator , string separator = "," , string startChar = "(" , string endChar = ")" )
3118
+ protected virtual List < string > GetExpressionsBetweenParenthesesOrOtherImbricableBrackets ( string expression , ref int i , bool checkSeparator , string separator = "," , string startChar = "(" , string endChar = ")" )
3122
3119
{
3123
3120
List < string > expressionsList = new List < string > ( ) ;
3124
3121
@@ -3223,7 +3220,9 @@ protected virtual bool DefaultFunctions(string name, List<string> args, out obje
3223
3220
}
3224
3221
else if ( OptionScriptEvaluateFunctionActive && name . Equals ( "ScriptEvaluate" , StringComparisonForCasing ) )
3225
3222
{
3223
+ bool oldInScript = inScript ;
3226
3224
result = ScriptEvaluate ( ( string ) Evaluate ( args [ 0 ] ) ) ;
3225
+ inScript = oldInScript ;
3227
3226
}
3228
3227
else
3229
3228
{
@@ -3700,7 +3699,7 @@ public static partial class OperatorsEvaluationsExtensions
3700
3699
{
3701
3700
public static IList < IDictionary < ExpressionOperator , Func < dynamic , dynamic , object > > > Copy ( this IList < IDictionary < ExpressionOperator , Func < dynamic , dynamic , object > > > operatorsEvaluations )
3702
3701
{
3703
- return ( IList < IDictionary < ExpressionOperator , Func < dynamic , dynamic , object > > > ) operatorsEvaluations
3702
+ return operatorsEvaluations
3704
3703
. Select ( dic => ( IDictionary < ExpressionOperator , Func < dynamic , dynamic , object > > ) new Dictionary < ExpressionOperator , Func < dynamic , dynamic , object > > ( dic ) )
3705
3704
. ToList ( ) ;
3706
3705
}
@@ -3790,7 +3789,7 @@ public partial class StronglyTypedVariable
3790
3789
3791
3790
public partial class ExpressionEvaluatorSyntaxErrorException : Exception
3792
3791
{
3793
- public ExpressionEvaluatorSyntaxErrorException ( ) : base ( )
3792
+ public ExpressionEvaluatorSyntaxErrorException ( )
3794
3793
{ }
3795
3794
3796
3795
public ExpressionEvaluatorSyntaxErrorException ( string message ) : base ( message )
@@ -3802,7 +3801,7 @@ public ExpressionEvaluatorSyntaxErrorException(string message, Exception innerEx
3802
3801
3803
3802
public partial class ExpressionEvaluatorSecurityException : Exception
3804
3803
{
3805
- public ExpressionEvaluatorSecurityException ( ) : base ( )
3804
+ public ExpressionEvaluatorSecurityException ( )
3806
3805
{ }
3807
3806
3808
3807
public ExpressionEvaluatorSecurityException ( string message ) : base ( message )
@@ -3814,8 +3813,8 @@ public ExpressionEvaluatorSecurityException(string message, Exception innerExcep
3814
3813
3815
3814
public partial class VariableEvaluationEventArg : EventArgs
3816
3815
{
3817
- private readonly Func < string , Type [ ] > evaluateGenericTypes = null ;
3818
- private readonly string genericTypes = null ;
3816
+ private readonly Func < string , Type [ ] > evaluateGenericTypes ;
3817
+ private readonly string genericTypes ;
3819
3818
3820
3819
/// <summary>
3821
3820
/// Constructor of the VariableEvaluationEventArg
@@ -3853,13 +3852,13 @@ public object Value
3853
3852
/// <summary>
3854
3853
/// if <c>true</c> the variable is affected, if <c>false</c> it means that the variable does not exist.
3855
3854
/// </summary>
3856
- public bool HasValue { get ; set ; } = false ;
3855
+ public bool HasValue { get ; set ; }
3857
3856
3858
3857
/// <summary>
3859
3858
/// In the case of on the fly instance property definition the instance of the object on which this Property is called.
3860
3859
/// Otherwise is set to null.
3861
3860
/// </summary>
3862
- public object This { get ; } = null ;
3861
+ public object This { get ; }
3863
3862
3864
3863
/// <summary>
3865
3864
/// A reference on the current expression evaluator.
@@ -3888,7 +3887,7 @@ public Type[] EvaluateGenericTypes()
3888
3887
}
3889
3888
}
3890
3889
3891
- public class VariablePreEvaluationEventArg : VariableEvaluationEventArg
3890
+ public partial class VariablePreEvaluationEventArg : VariableEvaluationEventArg
3892
3891
{
3893
3892
public VariablePreEvaluationEventArg ( string name , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
3894
3893
: base ( name , evaluator , onInstance , genericTypes , evaluateGenericTypes )
@@ -3897,14 +3896,14 @@ public VariablePreEvaluationEventArg(string name, ExpressionEvaluator evaluator
3897
3896
/// <summary>
3898
3897
/// If set to true cancel the evaluation of the current variable, field or property and throw an exception it does not exists
3899
3898
/// </summary>
3900
- public bool CancelEvaluation { get ; set ; } = false ;
3899
+ public bool CancelEvaluation { get ; set ; }
3901
3900
}
3902
3901
3903
3902
public partial class FunctionEvaluationEventArg : EventArgs
3904
3903
{
3905
- private readonly Func < string , object > evaluateFunc = null ;
3906
- private readonly Func < string , Type [ ] > evaluateGenericTypes = null ;
3907
- private readonly string genericTypes = null ;
3904
+ private readonly Func < string , object > evaluateFunc ;
3905
+ private readonly Func < string , Type [ ] > evaluateGenericTypes ;
3906
+ private readonly string genericTypes ;
3908
3907
3909
3908
public FunctionEvaluationEventArg ( string name , Func < string , object > evaluateFunc , List < string > args = null , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
3910
3909
{
@@ -3957,7 +3956,7 @@ public T EvaluateArg<T>(int index)
3957
3956
/// </summary>
3958
3957
public string Name { get ; }
3959
3958
3960
- private object returnValue = null ;
3959
+ private object returnValue ;
3961
3960
3962
3961
/// <summary>
3963
3962
/// To set the return value of the function
@@ -3975,13 +3974,13 @@ public object Value
3975
3974
/// <summary>
3976
3975
/// if <c>true</c> the function evaluation has been done, if <c>false</c> it means that the function does not exist.
3977
3976
/// </summary>
3978
- public bool FunctionReturnedValue { get ; set ; } = false ;
3977
+ public bool FunctionReturnedValue { get ; set ; }
3979
3978
3980
3979
/// <summary>
3981
3980
/// In the case of on the fly instance method definition the instance of the object on which this method (function) is called.
3982
3981
/// Otherwise is set to null.
3983
3982
/// </summary>
3984
- public object This { get ; } = null ;
3983
+ public object This { get ; }
3985
3984
3986
3985
/// <summary>
3987
3986
/// A reference on the current expression evaluator.
@@ -4010,7 +4009,7 @@ public Type[] EvaluateGenericTypes()
4010
4009
}
4011
4010
}
4012
4011
4013
- public class FunctionPreEvaluationEventArg : FunctionEvaluationEventArg
4012
+ public partial class FunctionPreEvaluationEventArg : FunctionEvaluationEventArg
4014
4013
{
4015
4014
public FunctionPreEvaluationEventArg ( string name , Func < string , object > evaluateFunc , List < string > args = null , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
4016
4015
: base ( name , evaluateFunc , args , evaluator , onInstance , genericTypes , evaluateGenericTypes )
@@ -4019,7 +4018,7 @@ public FunctionPreEvaluationEventArg(string name, Func<string, object> evaluateF
4019
4018
/// <summary>
4020
4019
/// If set to true cancel the evaluation of the current function or method and throw an exception that the function does not exists
4021
4020
/// </summary>
4022
- public bool CancelEvaluation { get ; set ; } = false ;
4021
+ public bool CancelEvaluation { get ; set ; }
4023
4022
}
4024
4023
4025
4024
#endregion
0 commit comments