Skip to content

Commit

Permalink
Merge pull request #36 from sveinungf/dev/srcgen-header-row
Browse files Browse the repository at this point in the history
Source generator - AddHeaderRow from property names
  • Loading branch information
sveinungf authored Feb 3, 2024
2 parents 4d4581c + 5746378 commit c57eaef
Show file tree
Hide file tree
Showing 46 changed files with 845 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties>? _ClassWithColumnOrderForAllProperties;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties> ClassWithColumnOrderForAllProperties => _ClassWithColumnOrderForAllProperties ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties> ClassWithColumnOrderForAllProperties => _ClassWithColumnOrderForAllProperties
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(6);
try
{
cells[0] = new StyledCell("LastName", styleId);
cells[1] = new StyledCell("FirstName", styleId);
cells[2] = new StyledCell("MiddleName", styleId);
cells[3] = new StyledCell("Employed", styleId);
cells[4] = new StyledCell("Age", styleId);
cells[5] = new StyledCell("Score", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties? obj, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties>? _ClassWithColumnOrderForSomeProperties;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties> ClassWithColumnOrderForSomeProperties => _ClassWithColumnOrderForSomeProperties ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties> ClassWithColumnOrderForSomeProperties => _ClassWithColumnOrderForSomeProperties
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(6);
try
{
cells[0] = new StyledCell("MiddleName", styleId);
cells[1] = new StyledCell("FirstName", styleId);
cells[2] = new StyledCell("Score", styleId);
cells[3] = new StyledCell("LastName", styleId);
cells[4] = new StyledCell("Employed", styleId);
cells[5] = new StyledCell("Age", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties? obj, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,22 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<MyNamespace.ClassWithDuplicateColumnOrdering>? _ClassWithDuplicateColumnOrdering;
public WorksheetRowTypeInfo<MyNamespace.ClassWithDuplicateColumnOrdering> ClassWithDuplicateColumnOrdering => _ClassWithDuplicateColumnOrdering ??= WorksheetRowMetadataServices.CreateObjectInfo<MyNamespace.ClassWithDuplicateColumnOrdering>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<MyNamespace.ClassWithDuplicateColumnOrdering> ClassWithDuplicateColumnOrdering => _ClassWithDuplicateColumnOrdering
??= WorksheetRowMetadataServices.CreateObjectInfo<MyNamespace.ClassWithDuplicateColumnOrdering>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("PropertyA", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithDuplicateColumnOrdering? obj, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,37 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes>? _ClassWithAllSupportedTypes;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes> ClassWithAllSupportedTypes => _ClassWithAllSupportedTypes ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes> ClassWithAllSupportedTypes => _ClassWithAllSupportedTypes
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(16);
try
{
cells[0] = new StyledCell("StringValue", styleId);
cells[1] = new StyledCell("NullableStringValue", styleId);
cells[2] = new StyledCell("IntValue", styleId);
cells[3] = new StyledCell("NullableIntValue", styleId);
cells[4] = new StyledCell("LongValue", styleId);
cells[5] = new StyledCell("NullableLongValue", styleId);
cells[6] = new StyledCell("FloatValue", styleId);
cells[7] = new StyledCell("NullableFloatValue", styleId);
cells[8] = new StyledCell("DoubleValue", styleId);
cells[9] = new StyledCell("NullableDoubleValue", styleId);
cells[10] = new StyledCell("DecimalValue", styleId);
cells[11] = new StyledCell("NullableDecimalValue", styleId);
cells[12] = new StyledCell("DateTimeValue", styleId);
cells[13] = new StyledCell("NullableDateTimeValue", styleId);
cells[14] = new StyledCell("BoolValue", styleId);
cells[15] = new StyledCell("NullableBoolValue", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 16), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes? obj, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance>? _ClassWithInheritance;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance> ClassWithInheritance => _ClassWithInheritance ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance> ClassWithInheritance => _ClassWithInheritance
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(2);
try
{
cells[0] = new StyledCell("Address", styleId);
cells[1] = new StyledCell("Country", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance? obj, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties>? _ClassWithMultipleProperties;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties> ClassWithMultipleProperties => _ClassWithMultipleProperties ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties> ClassWithMultipleProperties => _ClassWithMultipleProperties
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(6);
try
{
cells[0] = new StyledCell("FirstName", styleId);
cells[1] = new StyledCell("MiddleName", styleId);
cells[2] = new StyledCell("LastName", styleId);
cells[3] = new StyledCell("Age", styleId);
cells[4] = new StyledCell("Employed", styleId);
cells[5] = new StyledCell("Score", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties? obj, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,7 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties>? _ClassWithNoProperties;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties> ClassWithNoProperties => _ClassWithNoProperties ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties>(AddAsRowAsync, AddRangeAsRowsAsync);

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties? obj, CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);
}

private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties?> objs, CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
if (objs is null)
throw new ArgumentNullException(nameof(objs));
return AddRangeAsEmptyRowsAsync(spreadsheet, objs, token);
}

private static async ValueTask AddRangeAsEmptyRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties?> objs, CancellationToken token)
{
foreach (var _ in objs)
{
await spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);
}
}
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties> ClassWithNoProperties => _ClassWithNoProperties
??= EmptyWorksheetRowContext.CreateTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,7 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties>? _ClassWithNoProperties;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties> ClassWithNoProperties => _ClassWithNoProperties ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties>(AddAsRowAsync, AddRangeAsRowsAsync);

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties? obj, CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);
}

private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties?> objs, CancellationToken token)
{
if (spreadsheet is null)
throw new ArgumentNullException(nameof(spreadsheet));
if (objs is null)
throw new ArgumentNullException(nameof(objs));
return AddRangeAsEmptyRowsAsync(spreadsheet, objs, token);
}

private static async ValueTask AddRangeAsEmptyRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties?> objs, CancellationToken token)
{
foreach (var _ in objs)
{
await spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);
}
}
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties> ClassWithNoProperties => _ClassWithNoProperties
??= EmptyWorksheetRowContext.CreateTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithNoProperties>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,22 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty>? _ClassWithSingleProperty;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty> ClassWithSingleProperty => _ClassWithSingleProperty ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty> ClassWithSingleProperty => _ClassWithSingleProperty
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("Name", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,22 @@ public MyGenRowContext()
}

private WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty>? _ClassWithUnsupportedProperty;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty> ClassWithUnsupportedProperty => _ClassWithUnsupportedProperty ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty>(AddAsRowAsync, AddRangeAsRowsAsync);
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty> ClassWithUnsupportedProperty => _ClassWithUnsupportedProperty
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("Name", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
}
}

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty? obj, CancellationToken token)
{
Expand Down
Loading

0 comments on commit c57eaef

Please sign in to comment.