Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Ramstack.ExpressionParser/ExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ namespace Ramstack.Parsing;
/// <param name="binder">The binder that resolves the types, members, and methods referenced in the expression.</param>
public partial class ExpressionBuilder(Binder binder) : ExprVisitor<Expression>
{
/// <summary>
/// The overloads of the <c>string.Concat</c> method that the <c>+</c> operator with a string operand is bound to.
/// </summary>
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<MethodBase>()
.ToArray();

/// <summary>
/// Gets the binder that resolves the types, members, and methods referenced in the expression.
/// </summary>
Expand Down Expand Up @@ -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<MethodBase>()
.ToArray();

if (argumentTypes.Any(t => t != typeof(string)))
{
for (var i = 0; i < arguments.Count; i++)
Expand All @@ -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);
Expand Down