diff --git a/src/Ramstack.ExpressionParser/ExpressionBuilder.cs b/src/Ramstack.ExpressionParser/ExpressionBuilder.cs index 163c304..9120808 100644 --- a/src/Ramstack.ExpressionParser/ExpressionBuilder.cs +++ b/src/Ramstack.ExpressionParser/ExpressionBuilder.cs @@ -11,6 +11,17 @@ namespace Ramstack.Parsing; /// The binder that resolves the types, members, and methods referenced in the expression. public partial class ExpressionBuilder(Binder binder) : ExprVisitor { + /// + /// The overloads of the string.Concat method that the + operator with a string operand is bound to. + /// + private static readonly MethodBase[] ConcatMethods = typeof(string) + .GetMethods(BindingFlags.Public | BindingFlags.Static) + .Where(m => + m.Name == nameof(string.Concat) + && (m.CallingConvention & CallingConventions.VarArgs) == 0) + .Cast() + .ToArray(); + /// /// Gets the binder that resolves the types, members, and methods referenced in the expression. /// @@ -96,15 +107,6 @@ protected internal override Expression VisitBinary(Expr.Binary expr) Flatten(lhs); Flatten(rhs); - var methods = typeof(string) - .GetMethods( - BindingFlags.Public | BindingFlags.Static) - .Where(m => - m.Name == nameof(string.Concat) - && (m.CallingConvention & CallingConventions.VarArgs) == 0) - .Cast() - .ToArray(); - if (argumentTypes.Any(t => t != typeof(string))) { for (var i = 0; i < arguments.Count; i++) @@ -115,7 +117,7 @@ protected internal override Expression VisitBinary(Expr.Binary expr) } } - var cmi = (MethodInfo?)MethodResolver.ResolveMethod(methods, argumentTypes.ToArray())!; + var cmi = (MethodInfo?)MethodResolver.ResolveMethod(ConcatMethods, argumentTypes.ToArray())!; Debug.Assert(cmi is not null); var args = CreateInjectingArguments(cmi, arguments);