-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from sveinungf/dev/srcgen-caching
Source generator - Cachable pipeline
- Loading branch information
Showing
29 changed files
with
1,111 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...s/WorksheetRowGeneratorTests.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// <auto-generated /> | ||
#nullable enable | ||
using SpreadCheetah; | ||
using SpreadCheetah.SourceGeneration; | ||
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<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty>? _ClassWithSingleProperty; | ||
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) | ||
{ | ||
if (spreadsheet is null) | ||
throw new ArgumentNullException(nameof(spreadsheet)); | ||
if (obj is null) | ||
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token); | ||
return AddAsRowInternalAsync(spreadsheet, obj, token); | ||
} | ||
|
||
private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty?> 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, CancellationToken token) | ||
{ | ||
var cells = ArrayPool<DataCell>.Shared.Rent(1); | ||
try | ||
{ | ||
await AddCellsAsRowAsync(spreadsheet, obj, cells, token).ConfigureAwait(false); | ||
} | ||
finally | ||
{ | ||
ArrayPool<DataCell>.Shared.Return(cells, true); | ||
} | ||
} | ||
|
||
private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty?> objs, CancellationToken token) | ||
{ | ||
var cells = ArrayPool<DataCell>.Shared.Rent(1); | ||
try | ||
{ | ||
await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); | ||
} | ||
finally | ||
{ | ||
ArrayPool<DataCell>.Shared.Return(cells, true); | ||
} | ||
} | ||
|
||
private static async ValueTask AddEnumerableAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, IEnumerable<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty?> 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) | ||
{ | ||
if (obj is null) | ||
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token); | ||
|
||
cells[0] = new DataCell(obj.Name); | ||
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.