Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement support for inherited properties #50

Merged
merged 15 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
runs-on: windows-latest

steps:
- name: Configure Git to allow long paths
run: git config --system core.longpaths true
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns]
public record RecordClass2LevelOfInheritanceInheritedColumnsFirst(string OwnProperty, bool Value, string ClassProperty)
: RecordClassWithInheritedColumnsFirst(Value, ClassProperty);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns]
public record RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance(
string ClassProperty,
string Name,
bool Value,
int Age)
: RecordClassWithIgnoreInheritance(Name, Value, Age);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns]
public record RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast(
string OwnValue,
bool Value,
string ClassValue) :
RecordClassWithInheritedColumnsLast(Value, ClassValue);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns(InheritedColumnOrder.InheritedColumnsLast)]
public record RecordClass2LevelOfInheritanceInheritedColumnsLast(string OwnProperty, bool Value, string ClassProperty)
: RecordClassWithInheritedColumnsFirst(Value, ClassProperty);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns(InheritedColumnOrder.InheritedColumnsLast)]
public record RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance(
string ClassProperty,
string Name,
bool Value,
int Age)
: RecordClassWithIgnoreInheritance(Name, Value, Age);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns(InheritedColumnOrder.InheritedColumnsLast)]
public record RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst(
string OwnValue,
bool Value,
string ClassValue) :
RecordClassWithInheritedColumnsLast(Value, ClassValue);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

public record RecordClassWithIgnoreInheritance(string Name, bool Value, int Age)
: RecordClassWithSingleProperty(Value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns]
public record RecordClassWithInheritedColumnsFirst(bool Value, string ClassProperty)
: RecordClassWithSingleProperty(Value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using SpreadCheetah.SourceGeneration;

namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns;

[InheritColumns(InheritedColumnOrder.InheritedColumnsLast)]
public record RecordClassWithInheritedColumnsLast(bool Value, string ClassValue) : RecordClassWithSingleProperty(Value);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//HintName: MyNamespace.MyGenRowContext.g.cs
// <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.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst>? _RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst> RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst => _RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst>(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync);

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

private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst? 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.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst?> 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.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst obj, CancellationToken token)
{
var cells = ArrayPool<DataCell>.Shared.Rent(3);
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.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst?> objs, CancellationToken token)
{
var cells = ArrayPool<DataCell>.Shared.Rent(3);
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.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst?> 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.RecordClassWith2LevelOfInheritanceAndInheritedColumnsFirst? obj, DataCell[] cells, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);

cells[0] = new DataCell(obj.Name);
cells[1] = new DataCell(obj.Age);
cells[2] = new DataCell(obj.FirstName);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//HintName: MyNamespace.MyGenRowContext.g.cs
// <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.RecordClassWith2LevelOfInheritanceAndWithoutAttribute>? _RecordClassWith2LevelOfInheritanceAndWithoutAttribute;
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWith2LevelOfInheritanceAndWithoutAttribute> RecordClassWith2LevelOfInheritanceAndWithoutAttribute => _RecordClassWith2LevelOfInheritanceAndWithoutAttribute
??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWith2LevelOfInheritanceAndWithoutAttribute>(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("FirstName", 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.RecordClassWith2LevelOfInheritanceAndWithoutAttribute? 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.RecordClassWith2LevelOfInheritanceAndWithoutAttribute?> 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.RecordClassWith2LevelOfInheritanceAndWithoutAttribute 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.RecordClassWith2LevelOfInheritanceAndWithoutAttribute?> 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.RecordClassWith2LevelOfInheritanceAndWithoutAttribute?> 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.RecordClassWith2LevelOfInheritanceAndWithoutAttribute? obj, DataCell[] cells, CancellationToken token)
{
if (obj is null)
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);

cells[0] = new DataCell(obj.FirstName);
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token);
}
}
}
Loading
Loading