Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/System.Linq.Dynamic.Core/Parser/KeywordsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ internal class KeywordsHelper : IKeywordsHelper
private readonly Dictionary<string, AnyOf<string, Expression, Type>> _mappings;

// Pre-defined Types are not IgnoreCase
private static readonly Dictionary<string, Type> PreDefinedTypeMapping = new();
private static readonly Dictionary<string, Type> PreDefinedTypeMapping = [];

// Custom DefinedTypes are not IgnoreCase
private readonly Dictionary<string, Type> _customTypeMapping = new();
private readonly Dictionary<string, Type> _customTypeMapping = [];

static KeywordsHelper()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public int this[int i1]
get => i1 + "-" + i2;
}
}

private class ComplexParseLambda1Result
{
public int? Age;
Expand Down Expand Up @@ -730,7 +730,7 @@ public void DynamicExpressionParser_ParseLambda_Indexer1D()
// Assert
Check.That(result).Equals(4);
}

[Fact]
public void DynamicExpressionParser_ParseLambda_Indexer2D()
{
Expand All @@ -757,7 +757,7 @@ public void DynamicExpressionParser_ParseLambda_Indexer2D()
// Assert
Check.That(result).Equals("3-1");
}

[Fact]
public void DynamicExpressionParser_ParseLambda_IndexerParameterMismatch()
{
Expand All @@ -772,11 +772,32 @@ public void DynamicExpressionParser_ParseLambda_IndexerParameterMismatch()
{
Expression.Parameter(typeof(ClassWithIndexers), "myObj")
};

Assert.Throws<ParseException>(() =>
DynamicExpressionParser.ParseLambda(config, false, expressionParams, null, "myObj[3,\"1\",1]"));
}

[Fact]
public void DynamicExpressionParser_ParseLambda_Int16_CaseSensitive_IsValid()
{
// Act
var lambda = DynamicExpressionParser.ParseLambda(typeof(object), null, "Int16(5)");
var result = lambda.Compile().DynamicInvoke("x");

// Assert
result.Should().Be(5);
}

[Fact]
public void DynamicExpressionParser_ParseLambda_Int16_CaseInsensitive_Throws()
{
// Act
Action act = () => DynamicExpressionParser.ParseLambda(typeof(object), null, "int16(5)");

// Assert
act.Should().Throw<ParseException>();
}

[Fact]
public void DynamicExpressionParser_ParseLambda_DuplicateParameterNames_ThrowsException()
{
Expand Down Expand Up @@ -989,7 +1010,7 @@ public void DynamicExpressionParser_ParseLambda_HexToLong(string expression, lon
var parameters = Array.Empty<ParameterExpression>();

// Act
var lambda = DynamicExpressionParser.ParseLambda( parameters, typeof(long), expression);
var lambda = DynamicExpressionParser.ParseLambda(parameters, typeof(long), expression);
var result = lambda.Compile().DynamicInvoke();

// Assert
Expand Down Expand Up @@ -2372,6 +2393,6 @@ public DefaultDynamicLinqCustomTypeProviderForGenericExtensionMethod() : base(Pa
}

public override HashSet<Type> GetCustomTypes() =>
[..base.GetCustomTypes(), typeof(Methods), typeof(MethodsItemExtension)];
[.. base.GetCustomTypes(), typeof(Methods), typeof(MethodsItemExtension)];
}
}
Loading