@@ -53,6 +53,7 @@ public partial class ExpressionEvaluator
53
53
protected static readonly Regex lambdaExpressionRegex = new Regex ( @"^(?>\s*)(?<args>((?>\s*)[(](?>\s*)([\p{L}_](?>[\p{L}_0-9]*)(?>\s*)([,](?>\s*)[\p{L}_][\p{L}_0-9]*(?>\s*))*)?[)])|[\p{L}_](?>[\p{L}_0-9]*))(?>\s*)=>(?<expression>.*)$" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
54
54
protected static readonly Regex lambdaArgRegex = new Regex ( @"[\p{L}_](?>[\p{L}_0-9]*)" , RegexOptions . Compiled ) ;
55
55
protected static readonly Regex initInNewBeginningRegex = new Regex ( @"^(?>\s*){" , RegexOptions . Compiled ) ;
56
+ protected static readonly Regex functionArgKeywordsRegex = new Regex ( @"^\s*(?<keyword>out|ref)\s*(?<varName>[\p{L}_](?>[\p{L}_0-9]*))" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
56
57
57
58
// Depending on OptionInlineNamespacesEvaluationActive. Initialized in constructor
58
59
protected string InstanceCreationWithNewKeywordRegexPattern { get { return @"^new(?>\s*)((?<isAnonymous>[{{])|((?<name>[\p{L}_][\p{L}_0-9" + ( OptionInlineNamespacesEvaluationActive ? @"\." : string . Empty ) + @"]*)(?>\s*)(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?>\s*)((?<isfunction>[(])|(?<isArray>\[)|(?<isInit>[{{]))?))" ; } }
@@ -1894,7 +1895,28 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1894
1895
}
1895
1896
else
1896
1897
{
1897
- List < object > oArgs = funcArgs . ConvertAll ( Evaluate ) ;
1898
+ int argIndex = 0 ;
1899
+ List < OutOrRefArg > outOrRefArgs = new List < OutOrRefArg > ( ) ;
1900
+
1901
+ List < object > oArgs = funcArgs . ConvertAll ( arg =>
1902
+ {
1903
+ Match functionArgKeywordsMatch = functionArgKeywordsRegex . Match ( arg ) ;
1904
+ object argValue ;
1905
+
1906
+ if ( functionArgKeywordsMatch . Success )
1907
+ {
1908
+ OutOrRefArg outOrRefArg = new OutOrRefArg ( ) { Index = argIndex , VariableName = functionArgKeywordsMatch . Groups [ "varName" ] . Value } ;
1909
+ outOrRefArgs . Add ( outOrRefArg ) ;
1910
+ argValue = Evaluate ( outOrRefArg . VariableName ) ;
1911
+ }
1912
+ else
1913
+ {
1914
+ argValue = Evaluate ( arg ) ;
1915
+ }
1916
+
1917
+ argIndex ++ ;
1918
+ return argValue ;
1919
+ } ) ;
1898
1920
BindingFlags flag = DetermineInstanceOrStatic ( ref objType , ref obj , ref valueTypeNestingTrace ) ;
1899
1921
1900
1922
if ( ! OptionStaticMethodsCallActive && ( flag & BindingFlags . Static ) != 0 )
@@ -1942,7 +1964,9 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1942
1964
1943
1965
if ( methodInfo != null )
1944
1966
{
1945
- stack . Push ( methodInfo . Invoke ( isExtention ? null : obj , oArgs . ToArray ( ) ) ) ;
1967
+ object [ ] argsArray = oArgs . ToArray ( ) ;
1968
+ stack . Push ( methodInfo . Invoke ( isExtention ? null : obj , argsArray ) ) ;
1969
+ outOrRefArgs . ForEach ( outOrRefArg => variables [ outOrRefArg . VariableName ] = argsArray [ outOrRefArg . Index ] ) ;
1946
1970
}
1947
1971
else if ( objType . GetProperty ( varFuncName , StaticBindingFlag ) is PropertyInfo staticPropertyInfo
1948
1972
&& ( staticPropertyInfo . PropertyType . IsSubclassOf ( typeof ( Delegate ) ) || staticPropertyInfo . PropertyType == typeof ( Delegate ) )
@@ -3643,6 +3667,12 @@ public void AssignValue()
3643
3667
protected class NullConditionalNullValue
3644
3668
{ }
3645
3669
3670
+ protected class OutOrRefArg
3671
+ {
3672
+ public int Index { get ; set ; }
3673
+ public string VariableName { get ; set ; }
3674
+ }
3675
+
3646
3676
protected class DelegateEncaps
3647
3677
{
3648
3678
private readonly InternalDelegate lambda ;
0 commit comments