Skip to content

Commit

Permalink
Increase default max number of significant digits
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Feb 22, 2023
1 parent 53d0108 commit 581d45e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Bonsai.System/Bonsai.System.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>Bonsai System Library containing reactive infrastructure to interface with the underlying operating system.</Description>
<PackageTags>Bonsai Rx Reactive Extensions IO Serial Port Resources</PackageTags>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<VersionPrefix>2.7.0</VersionPrefix>
<VersionPrefix>2.7.1</VersionPrefix>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
Expand Down
23 changes: 16 additions & 7 deletions Bonsai.System/IO/CsvWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Bonsai.IO
public class CsvWriter : CombinatorExpressionBuilder
{
string delimiter;
static readonly Expression InvariantCulture = Expression.Constant(CultureInfo.InvariantCulture);
static readonly MethodInfo stringJoinMethod = typeof(string).GetMethods().Single(m => m.Name == nameof(string.Join) &&
m.GetParameters().Length == 2 &&
m.GetParameters()[1].ParameterType == typeof(string[]));
Expand Down Expand Up @@ -184,23 +185,31 @@ static bool IsNullable(Type type)
static Expression GetDataString(Expression expression)
{
if (expression.Type == typeof(string)) return expression;
if (expression.Type == typeof(float))
{
return Expression.Call(expression, nameof(ToString), null, Expression.Constant("G9"), InvariantCulture);
}
else if (expression.Type == typeof(double))
{
return Expression.Call(expression, nameof(ToString), null, Expression.Constant("G17"), InvariantCulture);
}
else if (expression.Type == typeof(DateTime) || expression.Type == typeof(DateTimeOffset))
{
return Expression.Call(expression, "ToString", null, Expression.Constant("o"));
return Expression.Call(expression, nameof(ToString), null, Expression.Constant("o"));
}
else if (expression.Type == typeof(IntPtr) || expression.Type == typeof(TimeSpan))
{
return Expression.Call(expression, "ToString", null);
return Expression.Call(expression, nameof(ToString), null);
}
else if (IsNullable(expression.Type))
{
var hasValue = Expression.Property(expression, "HasValue");
var value = Expression.Property(expression, "Value");
var hasValue = Expression.Property(expression, nameof(Nullable<int>.HasValue));
var value = Expression.Property(expression, nameof(Nullable<int>.Value));
return Expression.Condition(hasValue, GetDataString(value), Expression.Constant(string.Empty));
}
else
{
return Expression.Call(expression, "ToString", null, Expression.Constant(CultureInfo.InvariantCulture));
return Expression.Call(expression, nameof(ToString), null, InvariantCulture);
}
}

Expand Down Expand Up @@ -254,7 +263,7 @@ protected override Expression BuildCombinator(IEnumerable<Expression> arguments)
var converterExpression = Expression.Lambda(lineExpression, dataParameter);
lineExpression = Expression.Call(
typeof(CsvWriter),
"ListJoin",
nameof(ListJoin),
new[] { dataType },
inputParameter,
converterExpression,
Expand All @@ -281,7 +290,7 @@ protected override Expression BuildCombinator(IEnumerable<Expression> arguments)

var csvWriter = Expression.Constant(this);
var headerExpression = Expression.Constant(header);
return Expression.Call(csvWriter, "Process", new[] { parameterType }, source, headerExpression, writeAction);
return Expression.Call(csvWriter, nameof(Process), new[] { parameterType }, source, headerExpression, writeAction);
}

static string ListJoin<TSource>(IList<TSource> source, Func<TSource, string> converter, string separator)
Expand Down

0 comments on commit 581d45e

Please sign in to comment.