Skip to content
Open
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
12 changes: 6 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
dotnet-version: 11.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: ./benchmarks/MiniExcel.Benchmarks
- name: Build
run: dotnet build --no-restore
working-directory: ./benchmarks/MiniExcel.Benchmarks
- name: Benchmark
run: dotnet run -c Release -f net10.0
run: dotnet run -c Release -f net11.0
working-directory: ./benchmarks/MiniExcel.Benchmarks
env:
BenchmarkMode: Automatic
Expand All @@ -47,15 +47,15 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
dotnet-version: 11.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: ./benchmarks/MiniExcel.Benchmarks
- name: Build
run: dotnet build --no-restore
working-directory: ./benchmarks/MiniExcel.Benchmarks
- name: Benchmark
run: dotnet run -c Release -f net10.0
run: dotnet run -c Release -f net11.0
working-directory: ./benchmarks/MiniExcel.Benchmarks
env:
BenchmarkMode: Automatic
Expand All @@ -77,15 +77,15 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
dotnet-version: 11.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: ./benchmarks/MiniExcel.Benchmarks
- name: Build
run: dotnet build --no-restore
working-directory: ./benchmarks/MiniExcel.Benchmarks
- name: Benchmark
run: dotnet run -c Release -f net10.0
run: dotnet run -c Release -f net11.0
working-directory: ./benchmarks/MiniExcel.Benchmarks
env:
BenchmarkMode: Automatic
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
dotnet-version: 11.0.x

- name: Restore dependencies
run: dotnet restore
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
8.0.x
9.0.x
10.0.x
11.0.x
- name: Restore dependencies
run: dotnet restore
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net10.0;net11.0</TargetFrameworks>
Comment thread
michelebastione marked this conversation as resolved.
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<Version>2.0.0-preview.4</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>14</LangVersion>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
20 changes: 20 additions & 0 deletions src/MiniExcel.Core/Helpers/Polyfills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ public static ValueTask<ZipArchive> CreateAsync(Stream stream, ZipArchiveMode mo
}
}
#endif

#if NET11_0_OR_GREATER
extension(Convert)
{
/// <summary>Converts the specified double value to decimal using the same approximation applied by versions of .NET no greater than 10.</summary>
/// <remarks>
/// In .NET 11 conversion APIs such as <see cref="Decimal(double)" /> and <see cref="Convert.ToDecimal(double)" /> among others
/// have been changed to approximate the resulting value more accurately. Unfortunately this is a significant breaking change for us
/// as we relied upon this truncation to discard unwanted decimal digits when mapping doubles (our default numeric type) to decimals.
/// This method is therefore a workaround to ensure backwards compatibility with previous versions of the library.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static decimal ToDecimalWithLegacyApproximation(double value)
{
Span<char> text = stackalloc char[32];
value.TryFormat(text, out var length, "G15", CultureInfo.InvariantCulture);
return decimal.Parse(text[..length], NumberStyles.Float, CultureInfo.InvariantCulture);
}
}
#endif
}

#if NETSTANDARD2_0
Expand Down
7 changes: 6 additions & 1 deletion src/MiniExcel.Core/MiniExcelDataReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ public virtual byte GetByte(int i) => GetValue(i) is { } value

public virtual decimal GetDecimal(int i) => GetValue(i) switch
{
decimal d => d,
decimal dec => dec,
#if NET11_0_OR_GREATER
double f64 => Convert.ToDecimalWithLegacyApproximation(f64),
#else
double f64 => Convert.ToDecimal(f64, CultureInfo.InvariantCulture),
#endif
null => throw new InvalidOperationException("The value is null"),
var value => Convert.ToDecimal(value, MiniExcelConfiguration.Culture)
};
Expand Down
33 changes: 32 additions & 1 deletion src/MiniExcel.Core/Reflection/MiniExcelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ public static partial class MiniExcelMapper

else if (map.ExcludeNullableType == typeof(double))
{
if (double.TryParse(Convert.ToString(itemValue, config.Culture), NumberStyles.Any, config.Culture, out var doubleValue))
if (itemValue is double f64)
{
newValue = f64;
}
else if (double.TryParse(Convert.ToString(itemValue, config.Culture), NumberStyles.Any, config.Culture, out var doubleValue))
{
newValue = doubleValue;
}
Expand All @@ -227,6 +231,33 @@ public static partial class MiniExcelMapper
}
}

else if (map.ExcludeNullableType == typeof(decimal))
{
if (itemValue is decimal dec)
{
newValue = dec;
}
else if (itemValue is double f64)
{
#if NET11_0_OR_GREATER
newValue = Convert.ToDecimalWithLegacyApproximation(f64);
#else
newValue = Convert.ToDecimal(f64, CultureInfo.InvariantCulture);
#endif
}
else if (decimal.TryParse(Convert.ToString(itemValue, config.Culture), NumberStyles.Any, config.Culture, out var decimalValue))
{
newValue = decimalValue;
}
else
{
var invariantString = Convert.ToString(itemValue, CultureInfo.InvariantCulture);
newValue = decimal.TryParse(invariantString, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)
? value
: throw new InvalidCastException();
}
}

else if (map.ExcludeNullableType == typeof(bool))
{
var vs = itemValue?.ToString();
Expand Down
2 changes: 1 addition & 1 deletion tests/MiniExcel.Csv.Tests/MiniExcel.Csv.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);IDE0017;IDE0034;IDE0037;IDE0039;IDE0042;IDE0044;IDE0051;IDE0052;IDE0059;IDE0060;IDE0063;IDE1006;xUnit1004;CA1806;CA1816;CA1822;CA1825;CA1849;CA2000;CA2007;CA2208</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);IDE0017;IDE0034;IDE0037;IDE0039;IDE0042;IDE0044;IDE0051;IDE0052;IDE0059;IDE0060;IDE0063;IDE1006;xUnit1004;CA1806;CA1816;CA1822;CA1825;CA1849;CA2000;CA2007;CA2208</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion tests/MiniExcel.Tests.Common/MiniExcel.Tests.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>MiniExcelLib.Tests.Common</RootNamespace>
Expand Down
Loading