-
-
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 #34 from sveinungf/dev/srcgen-column-order
Source generator - Column ordering
- Loading branch information
Showing
93 changed files
with
1,256 additions
and
217 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
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
7 changes: 7 additions & 0 deletions
7
SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithInheritance.cs
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,7 @@ | ||
namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; | ||
|
||
public class ClassWithInheritance : ClassWithSingleProperty | ||
{ | ||
public string Address { get; set; } = ""; | ||
public string Country { get; set; } = ""; | ||
} |
24 changes: 24 additions & 0 deletions
24
...ourceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForAllProperties.cs
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,24 @@ | ||
using SpreadCheetah.SourceGeneration; | ||
|
||
namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering; | ||
|
||
public class ClassWithColumnOrderForAllProperties | ||
{ | ||
[ColumnOrder(2)] | ||
public string FirstName { get; set; } = ""; | ||
|
||
[ColumnOrder(3)] | ||
public string? MiddleName { get; set; } | ||
|
||
[ColumnOrder(1)] | ||
public string LastName { get; set; } = ""; | ||
|
||
[ColumnOrder(5)] | ||
public int Age { get; set; } | ||
|
||
[ColumnOrder(4)] | ||
public bool Employed { get; set; } | ||
|
||
[ColumnOrder(6)] | ||
public double Score { get; set; } | ||
} |
21 changes: 21 additions & 0 deletions
21
...urceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForSomeProperties.cs
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,21 @@ | ||
using SpreadCheetah.SourceGeneration; | ||
|
||
namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering; | ||
|
||
public class ClassWithColumnOrderForSomeProperties | ||
{ | ||
public string FirstName { get; set; } = ""; | ||
|
||
[ColumnOrder(-1000)] | ||
public string? MiddleName { get; set; } | ||
|
||
public string LastName { get; set; } = ""; | ||
|
||
[ColumnOrder(500)] | ||
public int Age { get; set; } | ||
|
||
public bool Employed { get; set; } | ||
|
||
[ColumnOrder(2)] | ||
public double Score { get; set; } | ||
} |
4 changes: 4 additions & 0 deletions
4
SpreadCheetah.SourceGenerator.SnapshotTest/Models/RecordClassWithInheritance.cs
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,4 @@ | ||
namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; | ||
|
||
public record RecordClassWithInheritance(string Name, bool Value, int Age) | ||
: RecordClassWithSingleProperty(Value); |
92 changes: 92 additions & 0 deletions
92
...r_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs
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,92 @@ | ||
//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.ColumnOrdering.ClassWithColumnOrderForAllProperties>? _ClassWithColumnOrderForAllProperties; | ||
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties> ClassWithColumnOrderForAllProperties => _ClassWithColumnOrderForAllProperties ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties>(AddAsRowAsync, AddRangeAsRowsAsync); | ||
|
||
private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties? 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.ColumnOrdering.ClassWithColumnOrderForAllProperties?> 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.ColumnOrdering.ClassWithColumnOrderForAllProperties obj, CancellationToken token) | ||
{ | ||
var cells = ArrayPool<DataCell>.Shared.Rent(6); | ||
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.ColumnOrdering.ClassWithColumnOrderForAllProperties?> objs, CancellationToken token) | ||
{ | ||
var cells = ArrayPool<DataCell>.Shared.Rent(6); | ||
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.ColumnOrdering.ClassWithColumnOrderForAllProperties?> 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) | ||
{ | ||
if (obj is null) | ||
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token); | ||
|
||
cells[0] = new DataCell(obj.LastName); | ||
cells[1] = new DataCell(obj.FirstName); | ||
cells[2] = new DataCell(obj.MiddleName); | ||
cells[3] = new DataCell(obj.Employed); | ||
cells[4] = new DataCell(obj.Age); | ||
cells[5] = new DataCell(obj.Score); | ||
return spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token); | ||
} | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
..._Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs
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,92 @@ | ||
//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.ColumnOrdering.ClassWithColumnOrderForSomeProperties>? _ClassWithColumnOrderForSomeProperties; | ||
public WorksheetRowTypeInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties> ClassWithColumnOrderForSomeProperties => _ClassWithColumnOrderForSomeProperties ??= WorksheetRowMetadataServices.CreateObjectInfo<SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties>(AddAsRowAsync, AddRangeAsRowsAsync); | ||
|
||
private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties? 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.ColumnOrdering.ClassWithColumnOrderForSomeProperties?> 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.ColumnOrdering.ClassWithColumnOrderForSomeProperties obj, CancellationToken token) | ||
{ | ||
var cells = ArrayPool<DataCell>.Shared.Rent(6); | ||
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.ColumnOrdering.ClassWithColumnOrderForSomeProperties?> objs, CancellationToken token) | ||
{ | ||
var cells = ArrayPool<DataCell>.Shared.Rent(6); | ||
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.ColumnOrdering.ClassWithColumnOrderForSomeProperties?> 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) | ||
{ | ||
if (obj is null) | ||
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token); | ||
|
||
cells[0] = new DataCell(obj.MiddleName); | ||
cells[1] = new DataCell(obj.FirstName); | ||
cells[2] = new DataCell(obj.Score); | ||
cells[3] = new DataCell(obj.LastName); | ||
cells[4] = new DataCell(obj.Employed); | ||
cells[5] = new DataCell(obj.Age); | ||
return spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token); | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...rator_Generate_ClassWithDuplicateColumnOrdering#MyNamespace.MyGenRowContext.g.verified.cs
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,87 @@ | ||
//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<MyNamespace.ClassWithDuplicateColumnOrdering>? _ClassWithDuplicateColumnOrdering; | ||
public WorksheetRowTypeInfo<MyNamespace.ClassWithDuplicateColumnOrdering> ClassWithDuplicateColumnOrdering => _ClassWithDuplicateColumnOrdering ??= WorksheetRowMetadataServices.CreateObjectInfo<MyNamespace.ClassWithDuplicateColumnOrdering>(AddAsRowAsync, AddRangeAsRowsAsync); | ||
|
||
private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithDuplicateColumnOrdering? 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<MyNamespace.ClassWithDuplicateColumnOrdering?> 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.ClassWithDuplicateColumnOrdering 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<MyNamespace.ClassWithDuplicateColumnOrdering?> 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<MyNamespace.ClassWithDuplicateColumnOrdering?> 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) | ||
{ | ||
if (obj is null) | ||
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token); | ||
|
||
cells[0] = new DataCell(obj.PropertyA); | ||
return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...mnOrderTests.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering.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,14 @@ | ||
{ | ||
Diagnostics: [ | ||
{ | ||
Id: SPCH1003, | ||
Title: Duplicate column ordering, | ||
Severity: Error, | ||
WarningLevel: 0, | ||
Location: : (8,5)-(8,19), | ||
MessageFormat: The type '{0}' has two or more properties with the same column order, | ||
Message: The type 'ClassWithDuplicateColumnOrdering' has two or more properties with the same column order, | ||
Category: SpreadCheetah.SourceGenerator | ||
} | ||
] | ||
} |
File renamed without changes.
Oops, something went wrong.