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

Convert BigInteger to Int64 when possible from Python #10096

Merged
merged 5 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 15 additions & 1 deletion src/DynamoUtilities/DataMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace Dynamo.Utilities
{
Expand Down Expand Up @@ -86,7 +87,20 @@ public object Marshal(object obj)
var applicable = marshalers.Where(pair => pair.Key.IsAssignableFrom(targetType));

if (!applicable.Any())
return obj;
{
if (!(obj is BigInteger bigInt)) return obj;

long int64;
try
{
int64 = (long)bigInt;
}
catch (OverflowException)
{
return bigInt;
}
return int64;
}

// Find the marshaler that operates on the closest base type of the target type.
var dispatchedMarshaler =
Expand Down
1 change: 1 addition & 0 deletions src/DynamoUtilities/DynamoUtilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down