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

use some more polyfill features #75

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageVersion Include="Polyfill" Version="6.2.0" />
<PackageVersion Include="Polyfill" Version="6.8.0" PrivateAssets="all" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="PublicApiGenerator" Version="11.1.0" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions SpreadCheetah.SourceGenerator.Test/Helpers/TestData.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using SpreadCheetah.SourceGenerator.Test.Helpers.Backporting;
using SpreadCheetah.SourceGenerator.Test.Models;
using Xunit;

namespace SpreadCheetah.SourceGenerator.Test.Helpers;

internal static class TestData
{
public static TheoryData<ObjectType> ObjectTypes => EnumHelper.GetValues<ObjectType>().ToTheoryData();
public static TheoryData<ObjectType> ObjectTypes => EnumPolyfill.GetValues<ObjectType>().ToTheoryData();
}
13 changes: 0 additions & 13 deletions SpreadCheetah.Test/Helpers/Backporting/EnumHelper.cs

This file was deleted.

6 changes: 3 additions & 3 deletions SpreadCheetah.Test/Helpers/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace SpreadCheetah.Test.Helpers;

internal static class TestData
{
private static readonly CellType[] CellTypeArray = EnumHelper.GetValues<CellType>();
private static readonly CellType[] CellTypeArray = EnumPolyfill.GetValues<CellType>();
private static readonly CellType[] StyledCellTypeArray = [CellType.StyledCell, CellType.Cell];
private static readonly CellValueType[] CellValueTypeArray = EnumHelper.GetValues<CellValueType>();
private static readonly RowCollectionType[] RowCollectionTypeArray = EnumHelper.GetValues<RowCollectionType>();
private static readonly CellValueType[] CellValueTypeArray = EnumPolyfill.GetValues<CellValueType>();
private static readonly RowCollectionType[] RowCollectionTypeArray = EnumPolyfill.GetValues<RowCollectionType>();

public static IEnumerable<object?[]> CellTypes()
{
Expand Down
11 changes: 5 additions & 6 deletions SpreadCheetah.Test/Tests/SpreadsheetStyledRowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using DocumentFormat.OpenXml.Spreadsheet;
using SpreadCheetah.Styling;
using SpreadCheetah.Test.Helpers;
using SpreadCheetah.Test.Helpers.Backporting;
using System.Globalization;
using Alignment = SpreadCheetah.Styling.Alignment;
using Border = SpreadCheetah.Styling.Border;
Expand Down Expand Up @@ -537,7 +536,7 @@ public async Task Spreadsheet_AddRow_DateTimeNumberFormat(bool withExplicitNumbe
Assert.True(actualCell.Style.Font.Italic);
}

public static IEnumerable<object?[]> BorderStyles() => TestData.CombineWithStyledCellTypes(EnumHelper.GetValues<BorderStyle>());
public static IEnumerable<object?[]> BorderStyles() => TestData.CombineWithStyledCellTypes(EnumPolyfill.GetValues<BorderStyle>());

[Theory]
[MemberData(nameof(BorderStyles))]
Expand Down Expand Up @@ -576,7 +575,7 @@ public async Task Spreadsheet_AddRow_BorderStyle(BorderStyle borderStyle, CellTy
Assert.Equal(XLBorderStyleValues.None, actualBorder.DiagonalBorder);
}

public static IEnumerable<object?[]> DiagonalBorderTypes() => TestData.CombineWithStyledCellTypes(EnumHelper.GetValues<DiagonalBorderType>());
public static IEnumerable<object?[]> DiagonalBorderTypes() => TestData.CombineWithStyledCellTypes(EnumPolyfill.GetValues<DiagonalBorderType>());

[Theory]
[MemberData(nameof(DiagonalBorderTypes))]
Expand Down Expand Up @@ -681,7 +680,7 @@ public async Task Spreadsheet_AddRow_MultipleBorders(CellType type, RowCollectio
Assert.Equal(XLColor.Black, actualBorder.DiagonalBorderColor);
}

public static IEnumerable<object?[]> HorizontalAlignments() => TestData.CombineWithStyledCellTypes(EnumHelper.GetValues<HorizontalAlignment>());
public static IEnumerable<object?[]> HorizontalAlignments() => TestData.CombineWithStyledCellTypes(EnumPolyfill.GetValues<HorizontalAlignment>());

[Theory]
[MemberData(nameof(HorizontalAlignments))]
Expand Down Expand Up @@ -715,7 +714,7 @@ public async Task Spreadsheet_AddRow_HorizontalAlignment(HorizontalAlignment ali
Assert.False(actualAlignment.WrapText);
}

public static IEnumerable<object?[]> VerticalAlignments() => TestData.CombineWithStyledCellTypes(EnumHelper.GetValues<VerticalAlignment>());
public static IEnumerable<object?[]> VerticalAlignments() => TestData.CombineWithStyledCellTypes(EnumPolyfill.GetValues<VerticalAlignment>());

[Theory]
[MemberData(nameof(VerticalAlignments))]
Expand Down Expand Up @@ -1150,7 +1149,7 @@ public async Task Spreadsheet_AddRow_ExplicitCellReferencesForLongStringValueSty
Assert.Equal(expectedRow1Refs, actualSheet2Refs);
}

public static IEnumerable<object?[]> ExplicitStandardNumberFormats() => TestData.CombineWithStyledCellTypes(EnumHelper.GetValues<StandardNumberFormat>());
public static IEnumerable<object?[]> ExplicitStandardNumberFormats() => TestData.CombineWithStyledCellTypes(EnumPolyfill.GetValues<StandardNumberFormat>());

[Theory]
[MemberData(nameof(ExplicitStandardNumberFormats))]
Expand Down
16 changes: 0 additions & 16 deletions SpreadCheetah/Helpers/Backporting/DictionaryExtensions.cs

This file was deleted.

12 changes: 0 additions & 12 deletions SpreadCheetah/Helpers/Backporting/StreamExtensions.cs

This file was deleted.

13 changes: 0 additions & 13 deletions SpreadCheetah/Helpers/EnumHelper.cs

This file was deleted.

2 changes: 1 addition & 1 deletion SpreadCheetah/Helpers/FileCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class FileCounter

public void AddEmbeddedImage(ImageType type)
{
Debug.Assert(type > ImageType.None && EnumHelper.IsDefined(type));
Debug.Assert(type > ImageType.None && EnumPolyfill.IsDefined(type));

if (type == ImageType.Png)
EmbeddedImageTypes |= EmbeddedImageTypes.Png;
Expand Down
2 changes: 1 addition & 1 deletion SpreadCheetah/Spreadsheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public StyleId AddStyle(Style style, string name, StyleNameVisibility? nameVisib
ThrowHelper.StyleNameStartsOrEndsWithWhiteSpace(nameof(name));
if (name.Equals("Normal", StringComparison.OrdinalIgnoreCase))
ThrowHelper.StyleNameCanNotEqualNormal(nameof(name));
if (nameVisibility is { } visibility && !EnumHelper.IsDefined(visibility))
if (nameVisibility is { } visibility && !EnumPolyfill.IsDefined(visibility))
ThrowHelper.EnumValueInvalid(nameof(nameVisibility), nameVisibility);

var styleManager = _styleManager ??= new(defaultDateTimeFormat: null);
Expand Down
4 changes: 2 additions & 2 deletions SpreadCheetah/Styling/Alignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public HorizontalAlignment Horizontal
get => _horizontal;
set
{
if (!EnumHelper.IsDefined(value))
if (!EnumPolyfill.IsDefined(value))
ThrowHelper.EnumValueInvalid(nameof(value), value);
else
_horizontal = value;
Expand All @@ -31,7 +31,7 @@ public VerticalAlignment Vertical
get => _vertical;
set
{
if (!EnumHelper.IsDefined(value))
if (!EnumPolyfill.IsDefined(value))
ThrowHelper.EnumValueInvalid(nameof(value), value);
else
_vertical = value;
Expand Down
2 changes: 1 addition & 1 deletion SpreadCheetah/Styling/NumberFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SpreadCheetah.Styling;
private NumberFormat(string? customFormat, StandardNumberFormat? standardFormat)
{
CustomFormat = customFormat.WithEnsuredMaxLength(255);
StandardFormat = (standardFormat is not { } format || EnumHelper.IsDefined(format))
StandardFormat = (standardFormat is not { } format || EnumPolyfill.IsDefined(format))
? standardFormat
: throw new ArgumentOutOfRangeException(nameof(standardFormat));
}
Expand Down
2 changes: 1 addition & 1 deletion SpreadCheetah/Validations/DataValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private DataValidation(
public ValidationErrorType ErrorType
{
get => _errorType;
set => _errorType = EnumHelper.IsDefined(value)
set => _errorType = EnumPolyfill.IsDefined(value)
? value
: throw new ArgumentOutOfRangeException(nameof(value), value, null);
}
Expand Down
2 changes: 1 addition & 1 deletion SpreadCheetah/Worksheets/WorksheetOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public WorksheetVisibility Visibility
get => _visibility;
set
{
if (!EnumHelper.IsDefined(value))
if (!EnumPolyfill.IsDefined(value))
ThrowHelper.EnumValueInvalid(nameof(value), value);
else
_visibility = value;
Expand Down