@@ -11,7 +11,7 @@ namespace System.Linq.Dynamic.Core.Parser;
1111
1212internal 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