Skip to content

Commit c1e3bbb

Browse files
committed
refactor
1 parent 84ea210 commit c1e3bbb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace System.Linq.Dynamic.Core.Parser;
1111

1212
internal class ExpressionHelper : IExpressionHelper
1313
{
14-
private readonly Expression _nullExpression = Expression.Constant(null);
14+
private static readonly Expression _nullExpression = Expression.Constant(null);
1515
private readonly IConstantExpressionWrapper _constantExpressionWrapper = new ConstantExpressionWrapper();
1616
private readonly ParsingConfig _parsingConfig;
1717

@@ -394,7 +394,7 @@ public bool TryConvertTypes(ref Expression left, ref Expression right)
394394

395395
if (left.Type == typeof(object))
396396
{
397-
if (left is ConditionalExpression ce)
397+
if (TryGetAsIndexerExpression(left, out var ce))
398398
{
399399
var rightTypeAsNullableType = TypeHelper.GetNullableType(right.Type);
400400

@@ -417,7 +417,7 @@ public bool TryConvertTypes(ref Expression left, ref Expression right)
417417
}
418418
else if (right.Type == typeof(object))
419419
{
420-
if (right is ConditionalExpression ce)
420+
if (TryGetAsIndexerExpression(right, out var ce))
421421
{
422422
var leftTypeAsNullableType = TypeHelper.GetNullableType(left.Type);
423423

@@ -577,4 +577,17 @@ private static object[] ConvertIfIEnumerableHasValues(IEnumerable? input)
577577

578578
return [];
579579
}
580+
581+
private static bool TryGetAsIndexerExpression(Expression expression, [NotNullWhen(true)] out ConditionalExpression? indexerExpresion)
582+
{
583+
indexerExpresion = expression as ConditionalExpression;
584+
if (indexerExpresion == null)
585+
{
586+
return false;
587+
}
588+
589+
return
590+
indexerExpresion.IfTrue.ToString().Contains(DynamicClass.IndexerName) &&
591+
indexerExpresion.Test.ToString().Contains("ContainsProperty");
592+
}
580593
}

0 commit comments

Comments
 (0)