Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate BigInteger literals in CSharpHelper #13911

Merged
merged 1 commit into from
Nov 7, 2018
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
10 changes: 9 additions & 1 deletion src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
Expand Down Expand Up @@ -161,7 +162,8 @@ public CSharpHelper([NotNull] IRelationalTypeMappingSource relationalTypeMapping
{ typeof(TimeSpan), (c, v) => c.Literal((TimeSpan)v) },
{ typeof(uint), (c, v) => c.Literal((uint)v) },
{ typeof(ulong), (c, v) => c.Literal((ulong)v) },
{ typeof(ushort), (c, v) => c.Literal((ushort)v) }
{ typeof(ushort), (c, v) => c.Literal((ushort)v) },
{ typeof(BigInteger), (c, v) => c.Literal((BigInteger)v) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wut, no trailing comma??,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just followin' the existing style :)

};

/// <summary>
Expand Down Expand Up @@ -497,6 +499,12 @@ public virtual string Literal(TimeSpan value)
/// </summary>
public virtual string Literal(ushort value) => "(ushort)" + value;

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string Literal(BigInteger value) => $"BigInteger.Parse(\"{value.ToString(NumberFormatInfo.InvariantInfo)}\", NumberFormatInfo.InvariantInfo)";

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
Expand Down
7 changes: 7 additions & 0 deletions test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Data.SqlTypes;
using System.Linq.Expressions;
using System.Numerics;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -213,6 +214,12 @@ public void Literal_works_when_MultidimensionalArray()
result);
}

[Fact]
public void Literal_works_when_BigInteger() =>
Literal_works(
new BigInteger(42),
"BigInteger.Parse(\"42\", NumberFormatInfo.InvariantInfo)");

[Fact]
public void UnknownLiteral_throws_when_unknown()
{
Expand Down