diff --git a/.editorconfig b/.editorconfig
index ff3ff70b..c468c5b9 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -156,7 +156,7 @@ dotnet_diagnostic.IDE0301.severity = warning
# IDE0305: Use collection expression for fluent
dotnet_diagnostic.IDE0305.severity = warning
-[{CellValueTruncateAttribute.cs,ColumnHeaderAttribute.cs,ColumnOrderAttribute.cs,ColumnWidthAttribute.cs,WorksheetRowAttribute.cs}]
+[{CellValueTruncateAttribute.cs,ColumnHeaderAttribute.cs,ColumnOrderAttribute.cs,CellStyleAttribute.cs,ColumnWidthAttribute.cs,WorksheetRowAttribute.cs}]
# CA1019: Define accessors for attribute arguments
dotnet_diagnostic.CA1019.severity = none
# CS9113: Parameter is unread
@@ -244,6 +244,9 @@ dotnet_diagnostic.MA0076.severity = none
# RCS1163: Unused parameter
dotnet_diagnostic.RCS1163.severity = warning
+# RCS1205: Order named arguments according to the order of parameters
+dotnet_diagnostic.RCS1205.severity = none
+
[{ColumnHeaderAttribute.cs,ColumnOrderAttribute.cs,WorksheetRowAttribute.cs}]
# RCS1163: Unused parameter
dotnet_diagnostic.RCS1163.severity = none
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 3ad67adc..739839ee 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -23,8 +23,7 @@
-
-
+
diff --git a/SpreadCheetah.Benchmark/SpreadCheetah.Benchmark.csproj b/SpreadCheetah.Benchmark/SpreadCheetah.Benchmark.csproj
index db605f8d..6e2e1753 100644
--- a/SpreadCheetah.Benchmark/SpreadCheetah.Benchmark.csproj
+++ b/SpreadCheetah.Benchmark/SpreadCheetah.Benchmark.csproj
@@ -10,7 +10,6 @@
-
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/SpreadCheetah.SourceGenerator.CSharp8Test/Models/BaseClass.cs b/SpreadCheetah.SourceGenerator.CSharp8Test/Models/BaseClass.cs
index 754009e9..6ed216df 100644
--- a/SpreadCheetah.SourceGenerator.CSharp8Test/Models/BaseClass.cs
+++ b/SpreadCheetah.SourceGenerator.CSharp8Test/Models/BaseClass.cs
@@ -1,7 +1,10 @@
-namespace SpreadCheetah.SourceGenerator.CSharp8Test.Models
+using SpreadCheetah.SourceGeneration;
+
+namespace SpreadCheetah.SourceGenerator.CSharp8Test.Models
{
public class BaseClass
{
+ [CellStyle("Id style")]
public string Id { get; }
protected BaseClass(string id)
diff --git a/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithMultipleProperties.cs b/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithMultipleProperties.cs
index 983b172f..6a8af5af 100644
--- a/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithMultipleProperties.cs
+++ b/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithMultipleProperties.cs
@@ -6,10 +6,13 @@ namespace SpreadCheetah.SourceGenerator.CSharp8Test.Models
public class ClassWithMultipleProperties : BaseClass
{
[ColumnHeader("Last name")]
+ [CellStyle("Last name style")]
[CellValueTruncate(20)]
public string LastName { get; }
+
[ColumnOrder(1)]
public string FirstName { get; }
+
[ColumnWidth(5)]
public int Age { get; }
diff --git a/SpreadCheetah.SourceGenerator.CSharp8Test/Tests/WorksheetRowGeneratorTests.cs b/SpreadCheetah.SourceGenerator.CSharp8Test/Tests/WorksheetRowGeneratorTests.cs
index aac7dea3..f481b2f8 100644
--- a/SpreadCheetah.SourceGenerator.CSharp8Test/Tests/WorksheetRowGeneratorTests.cs
+++ b/SpreadCheetah.SourceGenerator.CSharp8Test/Tests/WorksheetRowGeneratorTests.cs
@@ -1,4 +1,5 @@
using SpreadCheetah.SourceGenerator.CSharp8Test.Models;
+using SpreadCheetah.Styling;
using SpreadCheetah.TestHelpers.Assertions;
using System;
using System.IO;
@@ -24,6 +25,8 @@ public async Task Spreadsheet_AddAsRow_ClassWithMultipleProperties()
await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
{
await spreadsheet.StartWorksheetAsync("Sheet", ctx);
+ spreadsheet.AddStyle(new Style { Font = { Bold = true } }, "Id style");
+ spreadsheet.AddStyle(new Style { Font = { Italic = true } }, "Last name style");
// Act
await spreadsheet.AddAsRowAsync(obj, ctx);
@@ -39,6 +42,9 @@ public async Task Spreadsheet_AddAsRow_ClassWithMultipleProperties()
Assert.Equal(obj.Age, sheet["D1"].IntValue);
Assert.Equal(4, sheet.CellCount);
Assert.Equal(5, sheet.Column("D").Width, 4);
+
+ Assert.True(sheet["B1"].Style.Font.Bold);
+ Assert.True(sheet["C1"].Style.Font.Italic);
}
[Fact]
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs
index fa7bb0cc..110de321 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs
@@ -26,7 +26,10 @@ private static PortableExecutableReference[] GetAssemblyReferences()
];
}
- public static SettingsTask CompileAndVerify(string source, bool replaceEscapedLineEndings = false, params object?[] parameters) where T : IIncrementalGenerator, new()
+ public static SettingsTask CompileAndVerify(string source,
+ bool replaceEscapedLineEndings = false,
+ bool onlyDiagnostics = false,
+ params object?[] parameters) where T : IIncrementalGenerator, new()
{
var syntaxTree = CSharpSyntaxTree.ParseText(source);
var references = GetAssemblyReferences();
@@ -47,6 +50,9 @@ private static PortableExecutableReference[] GetAssemblyReferences()
var task = Verify(target, settings);
+ if (onlyDiagnostics)
+ task = task.IgnoreGeneratedResult(x => x.SourceText.ToString().Contains("public WorksheetRowTypeInfo<", StringComparison.Ordinal));
+
return parameters.Length > 0
? task.UseParameters(parameters)
: task;
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithEmptyCellStyle.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithEmptyCellStyle.verified.txt
new file mode 100644
index 00000000..c9f77694
--- /dev/null
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithEmptyCellStyle.verified.txt
@@ -0,0 +1,14 @@
+{
+ Diagnostics: [
+ {
+ Id: SPCH1006,
+ Title: Invalid attribute argument,
+ Severity: Error,
+ WarningLevel: 0,
+ Location: : (6,5)-(6,18),
+ MessageFormat: '{0}' is an invalid argument for attribute '{1}',
+ Message: '' is an invalid argument for attribute 'SpreadCheetah.SourceGeneration.CellStyleAttribute',
+ Category: SpreadCheetah.SourceGenerator
+ }
+ ]
+}
\ No newline at end of file
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithMultipleAttributes#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithMultipleAttributes#MyNamespace.MyGenRowContext.g.verified.cs
new file mode 100644
index 00000000..8ca91882
--- /dev/null
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithMultipleAttributes#MyNamespace.MyGenRowContext.g.verified.cs
@@ -0,0 +1,134 @@
+//HintName: MyNamespace.MyGenRowContext.g.cs
+//
+#nullable enable
+using SpreadCheetah;
+using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
+using System;
+using System.Buffers;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MyNamespace
+{
+ public partial class MyGenRowContext
+ {
+ private static MyGenRowContext? _default;
+ public static MyGenRowContext Default => _default ??= new MyGenRowContext();
+
+ public MyGenRowContext()
+ {
+ }
+
+ private WorksheetRowTypeInfo? _ClassWithCellStyle;
+ public WorksheetRowTypeInfo ClassWithCellStyle => _ClassWithCellStyle
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null, CreateWorksheetRowDependencyInfo0);
+
+ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo0(Spreadsheet spreadsheet)
+ {
+ var styleIds = new[]
+ {
+ spreadsheet.GetStyleId("Italic"),
+ spreadsheet.GetStyleId("Bold"),
+ };
+ return new WorksheetRowDependencyInfo(styleIds);
+ }
+
+ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(4);
+ try
+ {
+ cells[0] = new StyledCell("FirstName", styleId);
+ cells[1] = new StyledCell("LastName", styleId);
+ cells[2] = new StyledCell("YearOfBirth", styleId);
+ cells[3] = new StyledCell("Initials", styleId);
+ await spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token).ConfigureAwait(false);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellStyle? obj, CancellationToken token)
+ {
+ if (spreadsheet is null)
+ throw new ArgumentNullException(nameof(spreadsheet));
+ if (obj is null)
+ return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
+ return AddAsRowInternalAsync(spreadsheet, obj, token);
+ }
+
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
+ {
+ if (spreadsheet is null)
+ throw new ArgumentNullException(nameof(spreadsheet));
+ if (objs is null)
+ throw new ArgumentNullException(nameof(objs));
+ return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
+ }
+
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellStyle obj,
+ CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(4);
+ try
+ {
+ var worksheetRowDependencyInfo = spreadsheet.GetOrCreateWorksheetRowDependencyInfo(Default.ClassWithCellStyle);
+ var styleIds = worksheetRowDependencyInfo.StyleIds;
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(4);
+ try
+ {
+ var worksheetRowDependencyInfo = spreadsheet.GetOrCreateWorksheetRowDependencyInfo(Default.ClassWithCellStyle);
+ var styleIds = worksheetRowDependencyInfo.StyleIds;
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellStyle? obj,
+ StyledCell[] cells, IReadOnlyList styleIds, CancellationToken token)
+ {
+ if (obj is null)
+ return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
+
+ cells[0] = new StyledCell(new DataCell(obj.FirstName), styleIds[0]);
+ cells[1] = new StyledCell(new DataCell(obj.LastName), styleIds[1]);
+ cells[2] = new StyledCell(new DataCell(obj.YearOfBirth), null);
+ cells[3] = new StyledCell(new DataCell(obj.Initials), styleIds[1]);
+ return spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token);
+ }
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
+ }
+}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ContextWithTwoClassesWithCellStyle#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ContextWithTwoClassesWithCellStyle#MyNamespace.MyGenRowContext.g.verified.cs
new file mode 100644
index 00000000..893e2785
--- /dev/null
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ContextWithTwoClassesWithCellStyle#MyNamespace.MyGenRowContext.g.verified.cs
@@ -0,0 +1,233 @@
+//HintName: MyNamespace.MyGenRowContext.g.cs
+//
+#nullable enable
+using SpreadCheetah;
+using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
+using System;
+using System.Buffers;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MyNamespace
+{
+ public partial class MyGenRowContext
+ {
+ private static MyGenRowContext? _default;
+ public static MyGenRowContext Default => _default ??= new MyGenRowContext();
+
+ public MyGenRowContext()
+ {
+ }
+
+ private WorksheetRowTypeInfo? _ClassWithCellStyle;
+ public WorksheetRowTypeInfo ClassWithCellStyle => _ClassWithCellStyle
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null, CreateWorksheetRowDependencyInfo0);
+
+ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo0(Spreadsheet spreadsheet)
+ {
+ var styleIds = new[]
+ {
+ spreadsheet.GetStyleId("Italic"),
+ spreadsheet.GetStyleId("Bold"),
+ };
+ return new WorksheetRowDependencyInfo(styleIds);
+ }
+
+ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(4);
+ try
+ {
+ cells[0] = new StyledCell("FirstName", styleId);
+ cells[1] = new StyledCell("LastName", styleId);
+ cells[2] = new StyledCell("YearOfBirth", styleId);
+ cells[3] = new StyledCell("Initials", styleId);
+ await spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token).ConfigureAwait(false);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellStyle? obj, CancellationToken token)
+ {
+ if (spreadsheet is null)
+ throw new ArgumentNullException(nameof(spreadsheet));
+ if (obj is null)
+ return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
+ return AddAsRowInternalAsync(spreadsheet, obj, token);
+ }
+
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
+ {
+ if (spreadsheet is null)
+ throw new ArgumentNullException(nameof(spreadsheet));
+ if (objs is null)
+ throw new ArgumentNullException(nameof(objs));
+ return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
+ }
+
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellStyle obj,
+ CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(4);
+ try
+ {
+ var worksheetRowDependencyInfo = spreadsheet.GetOrCreateWorksheetRowDependencyInfo(Default.ClassWithCellStyle);
+ var styleIds = worksheetRowDependencyInfo.StyleIds;
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(4);
+ try
+ {
+ var worksheetRowDependencyInfo = spreadsheet.GetOrCreateWorksheetRowDependencyInfo(Default.ClassWithCellStyle);
+ var styleIds = worksheetRowDependencyInfo.StyleIds;
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellStyle? obj,
+ StyledCell[] cells, IReadOnlyList styleIds, CancellationToken token)
+ {
+ if (obj is null)
+ return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
+
+ cells[0] = new StyledCell(new DataCell(obj.FirstName), styleIds[0]);
+ cells[1] = new StyledCell(new DataCell(obj.LastName), styleIds[1]);
+ cells[2] = new StyledCell(new DataCell(obj.YearOfBirth), null);
+ cells[3] = new StyledCell(new DataCell(obj.Initials), styleIds[1]);
+ return spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token);
+ }
+
+ private WorksheetRowTypeInfo? _Class2WithCellStyle;
+ public WorksheetRowTypeInfo Class2WithCellStyle => _Class2WithCellStyle
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow1Async, AddAsRowAsync, AddRangeAsRowsAsync, null, CreateWorksheetRowDependencyInfo1);
+
+ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo1(Spreadsheet spreadsheet)
+ {
+ var styleIds = new[]
+ {
+ spreadsheet.GetStyleId("Red"),
+ spreadsheet.GetStyleId("Bold"),
+ };
+ return new WorksheetRowDependencyInfo(styleIds);
+ }
+
+ private static async ValueTask AddHeaderRow1Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(2);
+ try
+ {
+ cells[0] = new StyledCell("Id", styleId);
+ cells[1] = new StyledCell("Price", styleId);
+ await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.Class2WithCellStyle? obj, CancellationToken token)
+ {
+ if (spreadsheet is null)
+ throw new ArgumentNullException(nameof(spreadsheet));
+ if (obj is null)
+ return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
+ return AddAsRowInternalAsync(spreadsheet, obj, token);
+ }
+
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
+ {
+ if (spreadsheet is null)
+ throw new ArgumentNullException(nameof(spreadsheet));
+ if (objs is null)
+ throw new ArgumentNullException(nameof(objs));
+ return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
+ }
+
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.Class2WithCellStyle obj,
+ CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(2);
+ try
+ {
+ var worksheetRowDependencyInfo = spreadsheet.GetOrCreateWorksheetRowDependencyInfo(Default.Class2WithCellStyle);
+ var styleIds = worksheetRowDependencyInfo.StyleIds;
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
+ {
+ var cells = ArrayPool.Shared.Rent(2);
+ try
+ {
+ var worksheetRowDependencyInfo = spreadsheet.GetOrCreateWorksheetRowDependencyInfo(Default.Class2WithCellStyle);
+ var styleIds = worksheetRowDependencyInfo.StyleIds;
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(cells, true);
+ }
+ }
+
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.Class2WithCellStyle? obj,
+ StyledCell[] cells, IReadOnlyList styleIds, CancellationToken token)
+ {
+ if (obj is null)
+ return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
+
+ cells[0] = new StyledCell(new DataCell(obj.Id), styleIds[0]);
+ cells[1] = new StyledCell(new DataCell(obj.Price), styleIds[1]);
+ return spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token);
+ }
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
+ }
+}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt
index 9e7ee9e0..61af5b68 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt
@@ -2,6 +2,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -21,7 +22,8 @@ namespace MyNamespace
private WorksheetRowTypeInfo? _ClassWithSingleProperty;
public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -46,7 +48,9 @@ namespace MyNamespace
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -55,12 +59,15 @@ namespace MyNamespace
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -68,12 +75,18 @@ namespace MyNamespace
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -81,15 +94,9 @@ namespace MyNamespace
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -97,5 +104,12 @@ namespace MyNamespace
cells[0] = new DataCell(obj.Name);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes#MyNamespace.MyGenRowContext.g.verified.cs
index 214e9352..0f57f313 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithAllSupportedTypes;
public WorksheetRowTypeInfo ClassWithAllSupportedTypes => _ClassWithAllSupportedTypes
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -62,7 +64,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -71,12 +75,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(16);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -84,12 +91,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(16);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -97,15 +110,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -128,5 +135,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[15] = new DataCell(obj.NullableBoolValue);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 16), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs
index bb0fe16c..b43b200f 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithCellValueTruncate;
public WorksheetRowTypeInfo ClassWithCellValueTruncate => _ClassWithCellValueTruncate
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -47,7 +49,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -56,12 +60,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellValueTruncate obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellValueTruncate obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -69,12 +76,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -82,22 +95,22 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellValueTruncate? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellValueTruncate? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
- var p0 = obj.Name;
- cells[0] = p0 is null || p0.Length <= 10 ? new DataCell(p0) : new DataCell(p0.AsMemory(0, 10));
+ cells[0] = ConstructTruncatedDataCell(obj.Name, 10);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateOnInvalidType#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateOnInvalidType#MyNamespace.MyGenRowContext.g.verified.cs
index 43fa0662..1362233d 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateOnInvalidType#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateOnInvalidType#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithCellValueTruncate;
public WorksheetRowTypeInfo ClassWithCellValueTruncate => _ClassWithCellValueTruncate
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -47,7 +49,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -56,12 +60,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellValueTruncate obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellValueTruncate obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -69,12 +76,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -82,15 +95,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellValueTruncate? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellValueTruncate? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -98,5 +105,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[0] = new DataCell(obj.Year);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength#MyNamespace.MyGenRowContext.g.verified.cs
index a1af3c34..661850d0 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithCellValueTruncate;
public WorksheetRowTypeInfo ClassWithCellValueTruncate => _ClassWithCellValueTruncate
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -47,7 +49,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -56,12 +60,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellValueTruncate obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellValueTruncate obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -69,12 +76,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -82,15 +95,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithCellValueTruncate? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithCellValueTruncate? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -98,5 +105,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[0] = new DataCell(obj.Name);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs
index 139bc426..8d41062b 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithColumnHeaderForAllProperties;
public WorksheetRowTypeInfo ClassWithColumnHeaderForAllProperties => _ClassWithColumnHeaderForAllProperties
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -52,7 +54,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -61,12 +65,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithColumnHeaderForAllProperties obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithColumnHeaderForAllProperties obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(6);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -74,12 +81,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(6);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -87,15 +100,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithColumnHeaderForAllProperties? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithColumnHeaderForAllProperties? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -108,5 +115,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[5] = new DataCell(obj.Score);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs
index c711fee4..5be61b87 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithColumnOrderForAllProperties;
public WorksheetRowTypeInfo ClassWithColumnOrderForAllProperties => _ClassWithColumnOrderForAllProperties
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -52,7 +54,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -61,12 +65,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(6);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -74,12 +81,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(6);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -87,15 +100,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -108,5 +115,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[5] = new DataCell(obj.Score);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs
index 506990c2..6d2d5ae2 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithColumnOrderForSomeProperties;
public WorksheetRowTypeInfo ClassWithColumnOrderForSomeProperties => _ClassWithColumnOrderForSomeProperties
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -52,7 +54,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -61,12 +65,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(6);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -74,12 +81,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(6);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -87,15 +100,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -108,5 +115,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[5] = new DataCell(obj.Age);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs
index 8503796d..10acb5ba 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithColumnWidth;
public WorksheetRowTypeInfo ClassWithColumnWidth => _ClassWithColumnWidth
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, CreateWorksheetOptions0);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, CreateWorksheetOptions0);
private static SpreadCheetah.Worksheets.WorksheetOptions CreateWorksheetOptions0()
{
@@ -54,7 +56,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -63,12 +67,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithColumnWidth obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithColumnWidth obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -76,12 +83,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -89,15 +102,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithColumnWidth? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithColumnWidth? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -105,5 +112,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[0] = new DataCell(obj.Name);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth#MyNamespace.MyGenRowContext.g.verified.cs
index dd01af98..62358e01 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithColumnWidth;
public WorksheetRowTypeInfo ClassWithColumnWidth => _ClassWithColumnWidth
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -47,7 +49,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -56,12 +60,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithColumnWidth obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithColumnWidth obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -69,12 +76,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -82,15 +95,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithColumnWidth? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithColumnWidth? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -98,5 +105,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[0] = new DataCell(obj.Name);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering#MyNamespace.MyGenRowContext.g.verified.cs
index af1f5e23..f64ff8ee 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithDuplicateColumnOrdering;
public WorksheetRowTypeInfo ClassWithDuplicateColumnOrdering => _ClassWithDuplicateColumnOrdering
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -47,7 +49,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -56,12 +60,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithDuplicateColumnOrdering obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithDuplicateColumnOrdering obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -69,12 +76,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -82,15 +95,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithDuplicateColumnOrdering? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithDuplicateColumnOrdering? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -98,5 +105,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[0] = new DataCell(obj.PropertyA);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance#MyNamespace.MyGenRowContext.g.verified.cs
index 4adf0a2f..6ac93e1c 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithDuplicateColumnOrdering;
public WorksheetRowTypeInfo ClassWithDuplicateColumnOrdering => _ClassWithDuplicateColumnOrdering
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -47,7 +49,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -56,12 +60,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithDuplicateColumnOrdering obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithDuplicateColumnOrdering obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -69,12 +76,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(1);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -82,15 +95,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithDuplicateColumnOrdering? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithDuplicateColumnOrdering? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -98,5 +105,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[0] = new DataCell(obj.PropertyB);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs
index 259ece3b..c9994b71 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithInheritance;
public WorksheetRowTypeInfo ClassWithInheritance => _ClassWithInheritance
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -48,7 +50,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -57,12 +61,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(2);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -70,12 +77,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(2);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -83,15 +96,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token);
@@ -100,5 +107,12 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee
cells[1] = new DataCell(obj.Country);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token);
}
+
+ private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
+ {
+ return value is null || value.Length <= truncateLength
+ ? new DataCell(value)
+ : new DataCell(value.AsMemory(0, truncateLength));
+ }
}
}
diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInvalidPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInvalidPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs
index df5a1b8b..a6144723 100644
--- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInvalidPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs
+++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInvalidPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs
@@ -3,6 +3,7 @@
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
+using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -22,7 +23,8 @@ public MyGenRowContext()
private WorksheetRowTypeInfo? _ClassWithInvalidPropertyReferenceColumnHeaders;
public WorksheetRowTypeInfo ClassWithInvalidPropertyReferenceColumnHeaders => _ClassWithInvalidPropertyReferenceColumnHeaders
- ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);
+ ??= WorksheetRowMetadataServices.CreateObjectInfo(
+ AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null);
private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
@@ -53,7 +55,9 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My
return AddAsRowInternalAsync(spreadsheet, obj, token);
}
- private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
@@ -62,12 +66,15 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe
return AddRangeAsRowsInternalAsync(spreadsheet, objs, token);
}
- private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithInvalidPropertyReferenceColumnHeaders obj, CancellationToken token)
+ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithInvalidPropertyReferenceColumnHeaders obj,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(7);
try
{
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
}
finally
{
@@ -75,12 +82,18 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s
}
}
- private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, CancellationToken token)
+ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ IEnumerable objs,
+ CancellationToken token)
{
var cells = ArrayPool.Shared.Rent(7);
try
{
- await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false);
+ var styleIds = Array.Empty();
+ foreach (var obj in objs)
+ {
+ await AddCellsAsRowAsync(spreadsheet, obj, cells, styleIds, token).ConfigureAwait(false);
+ }
}
finally
{
@@ -88,15 +101,9 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads
}
}
- private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable objs, DataCell[] cells, CancellationToken token)
- {
- foreach (var obj in objs)
- {
- await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false);
- }
- }
-
- private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithInvalidPropertyReferenceColumnHeaders? obj, DataCell[] cells, CancellationToken token)
+ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet,
+ MyNamespace.ClassWithInvalidPropertyReferenceColumnHeaders? obj,
+ DataCell[] cells, IReadOnlyList styleIds, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory