Skip to content

Commit

Permalink
#90
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Jun 22, 2017
1 parent ea332ca commit cbb3900
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
23 changes: 10 additions & 13 deletions src/System.Linq.Dynamic.Core/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,12 @@ Expression ParseIn()
else if (left.Type != right.Type)
{
//check for nullable type match
if (!left.Type.GetTypeInfo().IsGenericType ||
left.Type.GetGenericTypeDefinition() != typeof(Nullable<>) ||
left.Type.GetTypeInfo().GetGenericTypeArguments()[0] != right.Type)
{
throw ParseError(op.Pos, Res.ExpressionTypeMismatch, left.Type);
}
//if (!left.Type.GetTypeInfo().IsGenericType ||
// left.Type.GetGenericTypeDefinition() != typeof(Nullable<>) ||
// left.Type.GetTypeInfo().GetGenericTypeArguments()[0] != right.Type)
//{
// throw ParseError(op.Pos, Res.ExpressionTypeMismatch, left.Type);
//}

CheckAndPromoteOperands(typeof(IEqualitySignatures), "==", ref left, ref right, op.Pos);
}
Expand Down Expand Up @@ -739,17 +739,14 @@ private ConstantExpression ParseEnumToConstantExpression(int pos, Type leftType,

private object ParseConstantExpressionToEnum(int pos, Type leftType, ConstantExpression constantExpr)
{
object parsedEnum = null;
try
{
if (constantExpr.Value is string)
{
return parsedEnum = Enum.Parse(GetNonNullableType(leftType), constantExpr.Value as string, true);
}
else
{
return parsedEnum = Enum.ToObject(leftType, constantExpr.Value);
return Enum.Parse(GetNonNullableType(leftType), (string)constantExpr.Value, true);
}

return Enum.ToObject(leftType, constantExpr.Value);
}
catch
{
Expand Down Expand Up @@ -975,7 +972,7 @@ Expression ParseIntegerLiteral()
return CreateLiteral(value, text);
}

if (value <= (int)short.MaxValue) return CreateLiteral((short)value, text);
// if (value <= (int)short.MaxValue) return CreateLiteral((short)value, text);
if (value <= int.MaxValue) return CreateLiteral((int)value, text);
if (value <= uint.MaxValue) return CreateLiteral((uint)value, text);
if (value <= long.MaxValue) return CreateLiteral((long)value, text);
Expand Down
28 changes: 14 additions & 14 deletions test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,20 @@ public void ExpressionTests_In_Enum()
Check.That(result2).ContainsExactly(expected);
}

[Fact]
public void ExpressionTests_In_Short()
{
// Arrange
var qry = new short[] { 1, 2, 3, 4, 5, 6, 7 }.AsQueryable();

// Act
var result = qry.Where("it in (1,2)");
var resultExpected = qry.Where(x => x == 1 || x == 2);

// Assert
Check.That(resultExpected.ToArray()).ContainsExactly(result.ToDynamicArray<short>());
}

[Fact]
public void ExpressionTests_In_String()
{
Expand Down Expand Up @@ -1430,20 +1444,6 @@ public void ExpressionTests_Type_Integer_Qualifiers_Exceptions()
Assert.Throws<ParseException>(() => values.Where("it < -2B"));
}

[Fact]
public void ExpressionTests_Type_Short()
{
// Arrange
var qry = new short[] { 1, 2, 3, 4, 5, 6, 7 }.AsQueryable();

// Act
var result = qry.Where("it in (1,2)");
var resultExpected = qry.Where(x => x == 1 || x == 2);

// Assert
Check.That(resultExpected.ToArray()).ContainsExactly(result.ToDynamicArray<short>());
}

[Fact]
public void ExpressionTests_Uri()
{
Expand Down

0 comments on commit cbb3900

Please sign in to comment.