diff --git a/.editorconfig b/.editorconfig index d7c6042e..be8df4c5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -276,6 +276,21 @@ dotnet_diagnostic.S927.severity = none # S2094: Classes should not be empty dotnet_diagnostic.S2094.severity = none +[{*SnapshotTest}/**.cs] +# S2699: Tests should include assertions (false positive for analyzer tests) +dotnet_diagnostic.S2699.severity = none + +############################### +# SpreadCheetah Options # +############################### +[{ClassWithNoPropertiesContext.cs,NoPropertiesContext.cs}] +# SPCH1001: Type has no properties with public getters +dotnet_diagnostic.SPCH1001.severity = none + +[{CustomTypeContext.cs}] +# SPCH1002: Type with unsupported property type +dotnet_diagnostic.SPCH1002.severity = none + ############################### # Threading.Analyzers Options # ############################### diff --git a/Directory.Packages.props b/Directory.Packages.props index cf5c1dec..9be360e9 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -23,6 +23,7 @@ + diff --git a/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithNoPropertiesContext.cs b/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithNoPropertiesContext.cs index b6c2c06a..04698b51 100644 --- a/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithNoPropertiesContext.cs +++ b/SpreadCheetah.SourceGenerator.CSharp8Test/Models/ClassWithNoPropertiesContext.cs @@ -3,7 +3,6 @@ namespace SpreadCheetah.SourceGenerator.CSharp8Test.Models { [WorksheetRow(typeof(ClassWithNoProperties))] - [WorksheetRowGenerationOptions(SuppressWarnings = true)] public partial class ClassWithNoPropertiesContext : WorksheetRowContext { } diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/AnalyzerTest.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/AnalyzerTest.cs new file mode 100644 index 00000000..6f9d0a1d --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/AnalyzerTest.cs @@ -0,0 +1,25 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Testing; +using Microsoft.CodeAnalysis.Testing; +using SpreadCheetah.SourceGeneration; +using SpreadCheetah.SourceGenerators; + +namespace SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; + +internal static class AnalyzerTest +{ + public static CSharpAnalyzerTest CreateContext() + { + return new CSharpAnalyzerTest + { + TestState = + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net80, + AdditionalReferences = + { + MetadataReference.CreateFromFile(typeof(WorksheetRowAttribute).Assembly.Location) + } + } + }; + } +} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs index 110de321..97721d31 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Helpers/TestHelper.cs @@ -28,7 +28,6 @@ private static PortableExecutableReference[] GetAssemblyReferences() public static SettingsTask CompileAndVerify(string source, bool replaceEscapedLineEndings = false, - bool onlyDiagnostics = false, params object?[] parameters) where T : IIncrementalGenerator, new() { var syntaxTree = CSharpSyntaxTree.ParseText(source); @@ -50,9 +49,6 @@ public static SettingsTask CompileAndVerify(string source, 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/Models/.editorconfig b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/.editorconfig deleted file mode 100644 index 74a55bed..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/.editorconfig +++ /dev/null @@ -1,5 +0,0 @@ -[*.cs] -# CA1815: Override equals and operator equals on value types -dotnet_diagnostic.CA1815.severity = none -# MA0048: File name must match type name -dotnet_diagnostic.MA0048.severity = none \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithAllSupportedTypes.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithAllSupportedTypes.cs deleted file mode 100644 index df0f7043..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithAllSupportedTypes.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public class ClassWithAllSupportedTypes -{ - public string StringValue { get; set; } = ""; - public string? NullableStringValue { get; set; } - public int IntValue { get; set; } - public int? NullableIntValue { get; set; } - public long LongValue { get; set; } - public long? NullableLongValue { get; set; } - public float FloatValue { get; set; } - public float? NullableFloatValue { get; set; } - public double DoubleValue { get; set; } - public double? NullableDoubleValue { get; set; } - public decimal DecimalValue { get; set; } - public decimal? NullableDecimalValue { get; set; } - public DateTime DateTimeValue { get; set; } - public DateTime? NullableDateTimeValue { get; set; } - public bool BoolValue { get; set; } - public bool? NullableBoolValue { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithInheritance.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithInheritance.cs deleted file mode 100644 index 637ffda3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithInheritance.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public class ClassWithInheritance : ClassWithSingleProperty -{ - public string Address { get; set; } = ""; - public string Country { get; set; } = ""; -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithMultipleProperties.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithMultipleProperties.cs deleted file mode 100644 index b9e8f8fb..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithMultipleProperties.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public class ClassWithMultipleProperties -{ - public string FirstName { get; set; } = ""; - public string? MiddleName { get; set; } - public string LastName { get; set; } = ""; - public int Age { get; set; } - public bool Employed { get; set; } - public double Score { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithNoProperties.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithNoProperties.cs deleted file mode 100644 index 264f0c04..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithNoProperties.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public class ClassWithNoProperties -{ -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithSingleProperty.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithSingleProperty.cs deleted file mode 100644 index d7113fff..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithSingleProperty.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public class ClassWithSingleProperty -{ - public string? Name { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithSinglePropertyAlternative.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithSinglePropertyAlternative.cs deleted file mode 100644 index 1d3e809f..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithSinglePropertyAlternative.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.AlternativeModels; - -#pragma warning disable MA0048 // File name must match type name -public class ClassWithSingleProperty -#pragma warning restore MA0048 // File name must match type name -{ - public string? Name { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithUnsupportedProperty.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithUnsupportedProperty.cs deleted file mode 100644 index b2fd72d2..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ClassWithUnsupportedProperty.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public class ClassWithUnsupportedProperty -{ - public string? Name { get; set; } - public Uri? HomepageUri { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithColumnHeaderForAllProperties.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithColumnHeaderForAllProperties.cs deleted file mode 100644 index 3afb0131..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithColumnHeaderForAllProperties.cs +++ /dev/null @@ -1,24 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader; - -public class ClassWithColumnHeaderForAllProperties -{ - [ColumnHeader("First name")] - public string FirstName { get; set; } = ""; - - [ColumnHeader("Middle name")] - public string? MiddleName { get; set; } - - [ColumnHeader("Last name")] - public string LastName { get; set; } = ""; - - [ColumnHeader("Age")] - public int Age { get; set; } - - [ColumnHeader("Employed (yes/no)")] - public bool Employed { get; set; } - - [ColumnHeader("Score (decimal)")] - public double Score { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithPropertyReferenceColumnHeaders.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithPropertyReferenceColumnHeaders.cs deleted file mode 100644 index 69ba1cfa..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithPropertyReferenceColumnHeaders.cs +++ /dev/null @@ -1,24 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader; - -public class ClassWithPropertyReferenceColumnHeaders -{ - [ColumnHeader(typeof(ColumnHeaderResources), nameof(ColumnHeaderResources.Header_FirstName))] - public string? FirstName { get; set; } - - [ColumnHeader(propertyName: nameof(ColumnHeaderResources.Header_LastName), type: typeof(ColumnHeaderResources))] - public string? LastName { get; set; } - - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderNationality))] - public string? Nationality { get; set; } - - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderAddressLine1))] - public string? AddressLine1 { get; set; } - - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderAddressLine2))] - public string? AddressLine2 { get; set; } - - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderAge))] - public int Age { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithSpecialCharacterColumnHeaders.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithSpecialCharacterColumnHeaders.cs deleted file mode 100644 index e269d2c0..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnHeader/ClassWithSpecialCharacterColumnHeaders.cs +++ /dev/null @@ -1,39 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader; - -public class ClassWithSpecialCharacterColumnHeaders -{ - [ColumnHeader("First name")] - public string? FirstName { get; set; } - - [ColumnHeader("")] - public string? LastName { get; set; } - - [ColumnHeader("Nationality (escaped characters \", \', \\)")] - public string? Nationality { get; set; } - - [ColumnHeader("Address line 1 (escaped characters \r\n, \t)")] - public string? AddressLine1 { get; set; } - - [ColumnHeader(@"Address line 2 (verbatim -string: "", \)")] - public string? AddressLine2 { get; set; } - - [ColumnHeader(""" - Age ( - raw - string - literal - ) - """)] - public int Age { get; set; } - - [ColumnHeader("Note (unicode escape sequence 🌉, \ud83d\udc4d, \xE7)")] - public string? Note { get; set; } - - private const string Constant = "This is a constant"; - - [ColumnHeader($"Note 2 (constant interpolated string: {Constant})")] - public string? Note2 { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForAllProperties.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForAllProperties.cs deleted file mode 100644 index 4da144a4..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForAllProperties.cs +++ /dev/null @@ -1,24 +0,0 @@ -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; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForSomeProperties.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForSomeProperties.cs deleted file mode 100644 index d6a3bfe4..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ColumnOrdering/ClassWithColumnOrderForSomeProperties.cs +++ /dev/null @@ -1,21 +0,0 @@ -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; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirst.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirst.cs deleted file mode 100644 index 64b53754..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirst.cs +++ /dev/null @@ -1,7 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -[InheritColumns] -public record RecordClass2LevelOfInheritanceInheritedColumnsFirst(string OwnProperty, bool Value, string ClassProperty) - : RecordClassWithInheritedColumnsFirst(Value, ClassProperty); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance.cs deleted file mode 100644 index 5dbfbbe1..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance.cs +++ /dev/null @@ -1,11 +0,0 @@ -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); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast.cs deleted file mode 100644 index 2507260d..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast.cs +++ /dev/null @@ -1,10 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -[InheritColumns] -public record RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast( - string OwnValue, - bool Value, - string ClassValue) : - RecordClassWithInheritedColumnsLast(Value, ClassValue); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLast.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLast.cs deleted file mode 100644 index ae2ec50f..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLast.cs +++ /dev/null @@ -1,7 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -[InheritColumns(DefaultColumnOrder = InheritedColumnsOrder.InheritedColumnsLast)] -public record RecordClass2LevelOfInheritanceInheritedColumnsLast(string OwnProperty, bool Value, string ClassProperty) - : RecordClassWithInheritedColumnsFirst(Value, ClassProperty); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance.cs deleted file mode 100644 index b06104d3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance.cs +++ /dev/null @@ -1,11 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -[InheritColumns(DefaultColumnOrder = InheritedColumnsOrder.InheritedColumnsLast)] -public record RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance( - string ClassProperty, - string Name, - bool Value, - int Age) - : RecordClassWithIgnoreInheritance(Name, Value, Age); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst.cs deleted file mode 100644 index 32ae28a3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst.cs +++ /dev/null @@ -1,10 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -[InheritColumns(DefaultColumnOrder = InheritedColumnsOrder.InheritedColumnsLast)] -public record RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst( - string OwnValue, - bool Value, - string ClassValue) : - RecordClassWithInheritedColumnsLast(Value, ClassValue); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithIgnoreInheritance.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithIgnoreInheritance.cs deleted file mode 100644 index dd8dfa7e..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithIgnoreInheritance.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -public record RecordClassWithIgnoreInheritance(string Name, bool Value, int Age) - : RecordClassWithSingleProperty(Value); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithInheritedColumnsFirst.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithInheritedColumnsFirst.cs deleted file mode 100644 index 56bbe1cf..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithInheritedColumnsFirst.cs +++ /dev/null @@ -1,7 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -[InheritColumns] -public record RecordClassWithInheritedColumnsFirst(bool Value, string ClassProperty) - : RecordClassWithSingleProperty(Value); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithInheritedColumnsLast.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithInheritedColumnsLast.cs deleted file mode 100644 index 1d24bede..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/InheritColumns/RecordClassWithInheritedColumnsLast.cs +++ /dev/null @@ -1,6 +0,0 @@ -using SpreadCheetah.SourceGeneration; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - -[InheritColumns(DefaultColumnOrder = InheritedColumnsOrder.InheritedColumnsLast)] -public record RecordClassWithInheritedColumnsLast(bool Value, string ClassValue) : RecordClassWithSingleProperty(Value); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ReadOnlyRecordStructWithSingleProperty.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ReadOnlyRecordStructWithSingleProperty.cs deleted file mode 100644 index 0f6df8f0..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ReadOnlyRecordStructWithSingleProperty.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public readonly record struct ReadOnlyRecordStructWithSingleProperty(int Value); diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ReadOnlyStructWithSingleProperty.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ReadOnlyStructWithSingleProperty.cs deleted file mode 100644 index 672028eb..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/ReadOnlyStructWithSingleProperty.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public readonly struct ReadOnlyStructWithSingleProperty -{ - public int Value { get; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/RecordClassWithSingleProperty.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/RecordClassWithSingleProperty.cs deleted file mode 100644 index 330a8063..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/RecordClassWithSingleProperty.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public record RecordClassWithSingleProperty(bool Value); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/RecordStructWithSingleProperty.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/RecordStructWithSingleProperty.cs deleted file mode 100644 index 02eefe45..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/RecordStructWithSingleProperty.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public record struct RecordStructWithSingleProperty(double Value); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/StructWithSingleProperty.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Models/StructWithSingleProperty.cs deleted file mode 100644 index 1dafaa43..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Models/StructWithSingleProperty.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Models; - -public struct StructWithSingleProperty -{ - public int Id { get; set; } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Caching_IncrementalSourceGeneratorCachingCorrectly.verified.txt similarity index 75% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Caching_IncrementalSourceGeneratorCachingCorrectly.verified.txt index 61af5b68..6420f7c9 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_CachingCorrectly.verified.txt +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Caching_IncrementalSourceGeneratorCachingCorrectly.verified.txt @@ -11,18 +11,18 @@ using System.Threading.Tasks; namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _MyRecord; + public WorksheetRowTypeInfo MyRecord => _MyRecord + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -39,7 +39,7 @@ namespace MyNamespace } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyRecord? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -49,7 +49,7 @@ namespace MyNamespace } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -60,7 +60,7 @@ namespace MyNamespace } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, + MyNamespace.MyRecord obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -76,7 +76,7 @@ namespace MyNamespace } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -95,7 +95,7 @@ namespace MyNamespace } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, + MyNamespace.MyRecord? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithEmptyCellStyle.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithEmptyCellStyle.verified.txt deleted file mode 100644 index 164f58f3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellStyle_ClassWithEmptyCellStyle.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (6,5)-(6,18), - Message: '' is an invalid argument for CellStyleAttribute, - Severity: Error, - Descriptor: { - Id: SPCH1006, - Title: Invalid attribute argument, - MessageFormat: '{0}' is an invalid argument for {1}, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassPropertyWithConverterAndCellValueTruncate.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassPropertyWithConverterAndCellValueTruncate.verified.txt deleted file mode 100644 index f10419a6..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassPropertyWithConverterAndCellValueTruncate.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (7,19)-(7,27), - Message: Having both the CellValueConverter and the CellValueTruncate attributes on a property is not supported, - Severity: Error, - Descriptor: { - Id: SPCH1008, - Title: Attribute combination not supported, - MessageFormat: Having both the {0} and the {1} attributes on a property is not supported, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithConverterThatDoesNotInheritCellValueConverter.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithConverterThatDoesNotInheritCellValueConverter.verified.txt deleted file mode 100644 index 82c21879..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithConverterThatDoesNotInheritCellValueConverter.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (5,5)-(5,54), - Message: Type 'MyNamespace.DecimalValueConverter' is an invalid argument for CellValueConverterAttribute because it does not inherit CellValueConverter, - Severity: Error, - Descriptor: { - Id: SPCH1007, - Title: Invalid attribute type argument, - MessageFormat: Type '{0}' is an invalid argument for {1} because it does not inherit {2}, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverter.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverter.verified.txt deleted file mode 100644 index 20ec0df3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverter.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (5,5)-(5,54), - Message: Type 'MyNamespace.DecimalValueConverter' is an invalid argument for CellValueConverterAttribute because it does not inherit CellValueConverter, - Severity: Error, - Descriptor: { - Id: SPCH1007, - Title: Invalid attribute type argument, - MessageFormat: Type '{0}' is an invalid argument for {1} because it does not inherit {2}, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverterOnComplexProperty.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverterOnComplexProperty.verified.txt deleted file mode 100644 index b01ad937..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverterOnComplexProperty.verified.txt +++ /dev/null @@ -1,31 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (5,5)-(5,48), - Message: Type 'MyNamespace.StringConverter' is an invalid argument for CellValueConverterAttribute because it does not inherit CellValueConverter, - Severity: Error, - Descriptor: { - Id: SPCH1007, - Title: Invalid attribute type argument, - MessageFormat: Type '{0}' is an invalid argument for {1} because it does not inherit {2}, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - }, - { - Location: : (16,1)-(16,65), - Message: The type 'ClassWithInvalidConverterOnComplexProperty' has a property of type 'Object' which is not supported as a cell value. The property will be ignored when creating the row., - Severity: Warning, - WarningLevel: 1, - Descriptor: { - Id: SPCH1002, - Title: Unsupported type for cell value, - MessageFormat: The type '{0}' has a property of type '{1}' which is not supported as a cell value. The property will be ignored when creating the row., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Warning, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithoutParameterlessConstructor.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithoutParameterlessConstructor.verified.txt deleted file mode 100644 index b9e5fce9..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithoutParameterlessConstructor.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (5,5)-(5,52), - Message: Type 'MyNamespace.FixedValueConverter' must have a public parameterless constructor, - Severity: Error, - Descriptor: { - Id: SPCH1009, - Title: Type must have a public parameterless constructor, - MessageFormat: Type '{0}' must have a public parameterless constructor, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueTruncate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs similarity index 100% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueTruncate_ClassWithCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithMultipleCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueTruncate_ClassWithMultipleCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs similarity index 100% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithMultipleCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueTruncate_ClassWithMultipleCellValueTruncate#MyNamespace.MyGenRowContext.g.verified.cs diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs similarity index 78% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs index 8d41062b..08cf5222 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithColumnHeaderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs @@ -21,9 +21,9 @@ public MyGenRowContext() { } - private WorksheetRowTypeInfo? _ClassWithColumnHeaderForAllProperties; - public WorksheetRowTypeInfo ClassWithColumnHeaderForAllProperties => _ClassWithColumnHeaderForAllProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _ClassWithColumnHeaderForAllProperties; + public WorksheetRowTypeInfo ClassWithColumnHeaderForAllProperties => _ClassWithColumnHeaderForAllProperties + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -45,7 +45,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithColumnHeaderForAllProperties? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithColumnHeaderForAllProperties? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -55,7 +55,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -66,7 +66,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithColumnHeaderForAllProperties obj, + MyNamespace.ClassWithColumnHeaderForAllProperties obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -82,7 +82,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -101,7 +101,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithColumnHeaderForAllProperties? obj, + MyNamespace.ClassWithColumnHeaderForAllProperties? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs similarity index 80% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs index 8ac95390..855c6dea 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithPropertyReferenceColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs @@ -21,9 +21,9 @@ public MyGenRowContext() { } - private WorksheetRowTypeInfo? _ClassWithPropertyReferenceColumnHeaders; - public WorksheetRowTypeInfo ClassWithPropertyReferenceColumnHeaders => _ClassWithPropertyReferenceColumnHeaders - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _ClassWithPropertyReferenceColumnHeaders; + public WorksheetRowTypeInfo ClassWithPropertyReferenceColumnHeaders => _ClassWithPropertyReferenceColumnHeaders + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -45,7 +45,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithPropertyReferenceColumnHeaders? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithPropertyReferenceColumnHeaders? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -55,7 +55,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -66,7 +66,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithPropertyReferenceColumnHeaders obj, + MyNamespace.ClassWithPropertyReferenceColumnHeaders obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -82,7 +82,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -101,7 +101,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithPropertyReferenceColumnHeaders? obj, + MyNamespace.ClassWithPropertyReferenceColumnHeaders? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithSpecialCharacterColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithSpecialCharacterColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs similarity index 79% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithSpecialCharacterColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithSpecialCharacterColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs index ba478ab6..ac08bffa 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithSpecialCharacterColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnHeader_ClassWithSpecialCharacterColumnHeaders#MyNamespace.MyGenRowContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyGenRowContext.g.cs // #nullable enable using SpreadCheetah; @@ -21,9 +21,9 @@ public MyGenRowContext() { } - private WorksheetRowTypeInfo? _ClassWithSpecialCharacterColumnHeaders; - public WorksheetRowTypeInfo ClassWithSpecialCharacterColumnHeaders => _ClassWithSpecialCharacterColumnHeaders - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _ClassWithSpecialCharacterColumnHeaders; + public WorksheetRowTypeInfo ClassWithSpecialCharacterColumnHeaders => _ClassWithSpecialCharacterColumnHeaders + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -47,7 +47,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithSpecialCharacterColumnHeaders? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithSpecialCharacterColumnHeaders? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -57,7 +57,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -68,7 +68,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithSpecialCharacterColumnHeaders obj, + MyNamespace.ClassWithSpecialCharacterColumnHeaders obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(8); @@ -84,7 +84,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(8); @@ -103,7 +103,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader.ClassWithSpecialCharacterColumnHeaders? obj, + MyNamespace.ClassWithSpecialCharacterColumnHeaders? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnOrder_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs similarity index 78% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnOrder_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs index 5be61b87..2f2068ee 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnOrder_ClassWithColumnOrderForAllProperties#MyNamespace.MyGenRowContext.g.verified.cs @@ -21,9 +21,9 @@ public MyGenRowContext() { } - private WorksheetRowTypeInfo? _ClassWithColumnOrderForAllProperties; - public WorksheetRowTypeInfo ClassWithColumnOrderForAllProperties => _ClassWithColumnOrderForAllProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _ClassWithColumnOrderForAllProperties; + public WorksheetRowTypeInfo ClassWithColumnOrderForAllProperties => _ClassWithColumnOrderForAllProperties + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -45,7 +45,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithColumnOrderForAllProperties? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -55,7 +55,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -66,7 +66,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties obj, + MyNamespace.ClassWithColumnOrderForAllProperties obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -82,7 +82,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -101,7 +101,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForAllProperties? obj, + MyNamespace.ClassWithColumnOrderForAllProperties? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnOrder_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs similarity index 78% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnOrder_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs index 6d2d5ae2..6d682d28 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnOrder_ClassWithColumnOrderForSomeProperties#MyNamespace.MyGenRowContext.g.verified.cs @@ -21,9 +21,9 @@ public MyGenRowContext() { } - private WorksheetRowTypeInfo? _ClassWithColumnOrderForSomeProperties; - public WorksheetRowTypeInfo ClassWithColumnOrderForSomeProperties => _ClassWithColumnOrderForSomeProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _ClassWithColumnOrderForSomeProperties; + public WorksheetRowTypeInfo ClassWithColumnOrderForSomeProperties => _ClassWithColumnOrderForSomeProperties + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -45,7 +45,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithColumnOrderForSomeProperties? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -55,7 +55,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -66,7 +66,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties obj, + MyNamespace.ClassWithColumnOrderForSomeProperties obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -82,7 +82,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(6); @@ -101,7 +101,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering.ClassWithColumnOrderForSomeProperties? obj, + MyNamespace.ClassWithColumnOrderForSomeProperties? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnWidth_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs similarity index 100% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnWidth_ClassWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithMultipleColumnWidths#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnWidth_ClassWithMultipleColumnWidths#MyNamespace.MyGenRowContext.g.verified.cs similarity index 100% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithMultipleColumnWidths#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnWidth_ClassWithMultipleColumnWidths#MyNamespace.MyGenRowContext.g.verified.cs diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoClassesWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnWidth_ContextWithTwoClassesWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs similarity index 100% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoClassesWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.ColumnWidth_ContextWithTwoClassesWithColumnWidth#MyNamespace.MyGenRowContext.g.verified.cs diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_InternalClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_DefaultAccessibility#MyNamespace.MyContext.g.verified.cs similarity index 79% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_InternalClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_DefaultAccessibility#MyNamespace.MyContext.g.verified.cs index 7a0f3422..1f359e2e 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_InternalClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_DefaultAccessibility#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - internal partial class MyGenRowContext + internal partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _InternalClassWithSingleProperty; - public WorksheetRowTypeInfo InternalClassWithSingleProperty => _InternalClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _MyRecord; + public WorksheetRowTypeInfo MyRecord => _MyRecord + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.InternalClassWithSingleProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyRecord? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -50,7 +50,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -61,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - MyNamespace.InternalClassWithSingleProperty obj, + MyNamespace.MyRecord obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -77,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -96,7 +96,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - MyNamespace.InternalClassWithSingleProperty? obj, + MyNamespace.MyRecord? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverterOnComplexProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_InternalAccessibility#MyNamespace.MyContext.g.verified.cs similarity index 75% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverterOnComplexProperty#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_InternalAccessibility#MyNamespace.MyContext.g.verified.cs index e8ccd309..1f359e2e 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.CellValueConverter_ClassWithInvalidConverterOnComplexProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_InternalAccessibility#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + internal partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _ClassWithInvalidConverterOnComplexProperty; - public WorksheetRowTypeInfo ClassWithInvalidConverterOnComplexProperty => _ClassWithInvalidConverterOnComplexProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _MyRecord; + public WorksheetRowTypeInfo MyRecord => _MyRecord + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -31,7 +31,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre var cells = ArrayPool.Shared.Rent(1); try { - cells[0] = new StyledCell("Property2", styleId); + cells[0] = new StyledCell("Name", styleId); await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); } finally @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithInvalidConverterOnComplexProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyRecord? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -50,7 +50,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, My } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -61,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - MyNamespace.ClassWithInvalidConverterOnComplexProperty obj, + MyNamespace.MyRecord obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -77,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -96,13 +96,13 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - MyNamespace.ClassWithInvalidConverterOnComplexProperty? obj, + MyNamespace.MyRecord? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - cells[0] = new DataCell(obj.Property2); + cells[0] = new DataCell(obj.Name); return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token); } diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoSimilarWorksheetRowAttributes#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoContextClasses#MyNamespace.MyContextA.g.verified.cs similarity index 74% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoSimilarWorksheetRowAttributes#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoContextClasses#MyNamespace.MyContextA.g.verified.cs index 46b79639..e02fc1f4 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoSimilarWorksheetRowAttributes#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoContextClasses#MyNamespace.MyContextA.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContextA.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContextA { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContextA? _default; + public static MyContextA Default => _default ??= new MyContextA(); - public MyGenRowContext() + public MyContextA() { } - private WorksheetRowTypeInfo? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _RecordA; + public WorksheetRowTypeInfo RecordA => _RecordA + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.RecordA? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -50,7 +50,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -61,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, + MyNamespace.RecordA obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -77,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -96,7 +96,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, + MyNamespace.RecordA? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_StructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoContextClasses#MyNamespace.MyContextB.g.verified.cs similarity index 73% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_StructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoContextClasses#MyNamespace.MyContextB.g.verified.cs index 12bd74e0..0b0eccc0 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_StructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoContextClasses#MyNamespace.MyContextB.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContextB.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContextB { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContextB? _default; + public static MyContextB Default => _default ??= new MyContextB(); - public MyGenRowContext() + public MyContextB() { } - private WorksheetRowTypeInfo? _StructWithSingleProperty; - public WorksheetRowTypeInfo StructWithSingleProperty => _StructWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _RecordB; + public WorksheetRowTypeInfo RecordB => _RecordB + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,15 +40,17 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.StructWithSingleProperty obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.RecordB? 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, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -59,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.StructWithSingleProperty obj, + MyNamespace.RecordB obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -75,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -94,9 +96,12 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.StructWithSingleProperty obj, + MyNamespace.RecordB? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { + if (obj is null) + return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); + cells[0] = new DataCell(obj.Id); return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token); } diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoSimilarWorksheetRowAttributes#MyNamespace.MyContext.g.verified.cs similarity index 74% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoSimilarWorksheetRowAttributes#MyNamespace.MyContext.g.verified.cs index 46b79639..88d79601 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoSimilarWorksheetRowAttributes#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _MyRecord; + public WorksheetRowTypeInfo MyRecord => _MyRecord + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, NamespaceA.MyRecord? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -50,7 +50,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -61,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, + NamespaceA.MyRecord obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -77,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -96,7 +96,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, + NamespaceA.MyRecord? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributes#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoWorksheetRowAttributes#MyNamespace.MyContext.g.verified.cs similarity index 66% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributes#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoWorksheetRowAttributes#MyNamespace.MyContext.g.verified.cs index 4d5d8512..72ad0747 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributes#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoWorksheetRowAttributes#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _RecordA; + public WorksheetRowTypeInfo RecordA => _RecordA + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.RecordA? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -50,7 +50,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -61,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, + MyNamespace.RecordA obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -77,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -96,7 +96,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, + MyNamespace.RecordA? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) @@ -106,23 +106,18 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token); } - private WorksheetRowTypeInfo? _ClassWithMultipleProperties; - public WorksheetRowTypeInfo ClassWithMultipleProperties => _ClassWithMultipleProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _RecordB; + public WorksheetRowTypeInfo RecordB => _RecordB + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow1Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow1Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) { - var cells = ArrayPool.Shared.Rent(6); + var cells = ArrayPool.Shared.Rent(1); 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); + cells[0] = new StyledCell("Id", styleId); + await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); } finally { @@ -130,7 +125,7 @@ private static async ValueTask AddHeaderRow1Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.RecordB? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -140,7 +135,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -151,10 +146,10 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties obj, + MyNamespace.RecordB obj, CancellationToken token) { - var cells = ArrayPool.Shared.Rent(6); + var cells = ArrayPool.Shared.Rent(1); try { var styleIds = Array.Empty(); @@ -167,10 +162,10 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { - var cells = ArrayPool.Shared.Rent(6); + var cells = ArrayPool.Shared.Rent(1); try { var styleIds = Array.Empty(); @@ -186,19 +181,14 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties? obj, + MyNamespace.RecordB? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - cells[0] = new DataCell(obj.FirstName); - cells[1] = new DataCell(obj.MiddleName); - cells[2] = new DataCell(obj.LastName); - cells[3] = new DataCell(obj.Age); - cells[4] = new DataCell(obj.Employed); - cells[5] = new DataCell(obj.Score); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 6), token); + cells[0] = new DataCell(obj.Id); + return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token); } private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning#MyNamespace.MyContext.g.verified.cs similarity index 74% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning#MyNamespace.MyContext.g.verified.cs index e33b8b92..fd0957cc 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.Context_TwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _ClassWithUnsupportedProperty; - public WorksheetRowTypeInfo ClassWithUnsupportedProperty => _ClassWithUnsupportedProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _RecordA; + public WorksheetRowTypeInfo RecordA => _RecordA + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.RecordA? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -50,7 +50,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -61,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty obj, + MyNamespace.RecordA obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -77,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -96,7 +96,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty? obj, + MyNamespace.RecordA? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) @@ -106,9 +106,9 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee return spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token); } - private WorksheetRowTypeInfo? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _RecordB; + public WorksheetRowTypeInfo RecordB => _RecordB + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow1Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow1Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -125,7 +125,7 @@ private static async ValueTask AddHeaderRow1Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.RecordB? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -135,7 +135,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -146,7 +146,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, + MyNamespace.RecordB obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -162,7 +162,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -181,7 +181,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, + MyNamespace.RecordB? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.PropertyType_ClassWithAllSupportedTypes#MyNamespace.MyContext.g.verified.cs similarity index 81% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.PropertyType_ClassWithAllSupportedTypes#MyNamespace.MyContext.g.verified.cs index 0f57f313..46fe419c 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.PropertyType_ClassWithAllSupportedTypes#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _ClassWithAllSupportedTypes; - public WorksheetRowTypeInfo ClassWithAllSupportedTypes => _ClassWithAllSupportedTypes - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _ClassWithAllSupportedTypes; + public WorksheetRowTypeInfo ClassWithAllSupportedTypes => _ClassWithAllSupportedTypes + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -55,7 +55,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.ClassWithAllSupportedTypes? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -65,7 +65,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -76,7 +76,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes obj, + MyNamespace.ClassWithAllSupportedTypes obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(16); @@ -92,7 +92,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(16); @@ -111,7 +111,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithAllSupportedTypes? obj, + MyNamespace.ClassWithAllSupportedTypes? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.PropertyType_ClassWithIndexer#MyNamespace.MyContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.PropertyType_ClassWithIndexer#MyNamespace.MyContext.g.verified.cs new file mode 100644 index 00000000..5779297d --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.PropertyType_ClassWithIndexer#MyNamespace.MyContext.g.verified.cs @@ -0,0 +1,35 @@ +//HintName: MyNamespace.MyContext.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 MyContext + { + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); + + public MyContext() + { + } + + private WorksheetRowTypeInfo? _MyClass; + public WorksheetRowTypeInfo MyClass => _MyClass + ??= EmptyWorksheetRowContext.CreateTypeInfo(); + + 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.RowType_ClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs new file mode 100644 index 00000000..bc632f90 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs @@ -0,0 +1,116 @@ +//HintName: MyNamespace.MyContext.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 MyContext + { + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); + + public MyContext() + { + } + + private WorksheetRowTypeInfo? _MyClass; + public WorksheetRowTypeInfo MyClass => _MyClass + ??= WorksheetRowMetadataServices.CreateObjectInfo( + AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); + + private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + cells[0] = new StyledCell("Name", styleId); + await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); + } + finally + { + ArrayPool.Shared.Return(cells, true); + } + } + + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyClass? 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.MyClass obj, + CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + var styleIds = Array.Empty(); + 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(1); + try + { + var styleIds = Array.Empty(); + 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.MyClass? obj, + DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) + { + if (obj is null) + return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); + + 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.RowType_InternalClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_InternalClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs new file mode 100644 index 00000000..79a5ef20 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_InternalClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs @@ -0,0 +1,116 @@ +//HintName: MyNamespace.MyContext.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 +{ + internal partial class MyContext + { + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); + + public MyContext() + { + } + + private WorksheetRowTypeInfo? _MyInternalClass; + public WorksheetRowTypeInfo MyInternalClass => _MyInternalClass + ??= WorksheetRowMetadataServices.CreateObjectInfo( + AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); + + private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + cells[0] = new StyledCell("Name", styleId); + await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); + } + finally + { + ArrayPool.Shared.Return(cells, true); + } + } + + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyInternalClass? 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.MyInternalClass obj, + CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + var styleIds = Array.Empty(); + 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(1); + try + { + var styleIds = Array.Empty(); + 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.MyInternalClass? obj, + DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) + { + if (obj is null) + return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); + + 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_RecordStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ReadOnlyRecordStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs similarity index 72% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ReadOnlyRecordStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs index 698b7e5e..d3471da7 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ReadOnlyRecordStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _RecordStructWithSingleProperty; - public WorksheetRowTypeInfo RecordStructWithSingleProperty => _RecordStructWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _MyReadOnlyRecordStruct; + public WorksheetRowTypeInfo MyReadOnlyRecordStruct => _MyReadOnlyRecordStruct + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordStructWithSingleProperty obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyReadOnlyRecordStruct obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -48,7 +48,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -59,7 +59,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordStructWithSingleProperty obj, + MyNamespace.MyReadOnlyRecordStruct obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -75,7 +75,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -94,7 +94,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordStructWithSingleProperty obj, + MyNamespace.MyReadOnlyRecordStruct obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { cells[0] = new DataCell(obj.Value); diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ReadOnlyStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ReadOnlyStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs similarity index 72% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ReadOnlyStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ReadOnlyStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs index a6d04569..a18fb281 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ReadOnlyStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_ReadOnlyStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _ReadOnlyStructWithSingleProperty; - public WorksheetRowTypeInfo ReadOnlyStructWithSingleProperty => _ReadOnlyStructWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _MyReadOnlyStruct; + public WorksheetRowTypeInfo MyReadOnlyStruct => _MyReadOnlyStruct + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ReadOnlyStructWithSingleProperty obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyReadOnlyStruct obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -48,7 +48,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -59,7 +59,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ReadOnlyStructWithSingleProperty obj, + MyNamespace.MyReadOnlyStruct obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -75,7 +75,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -94,7 +94,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ReadOnlyStructWithSingleProperty obj, + MyNamespace.MyReadOnlyStruct obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { cells[0] = new DataCell(obj.Value); diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_RecordClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs similarity index 73% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_RecordClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs index 2f8d3bcd..b55d604e 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_RecordClassWithSingleProperty#MyNamespace.MyContext.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs +//HintName: MyNamespace.MyContext.g.cs // #nullable enable using SpreadCheetah; @@ -12,18 +12,18 @@ namespace MyNamespace { - public partial class MyGenRowContext + public partial class MyContext { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); - public MyGenRowContext() + public MyContext() { } - private WorksheetRowTypeInfo? _RecordClassWithSingleProperty; - public WorksheetRowTypeInfo RecordClassWithSingleProperty => _RecordClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( + private WorksheetRowTypeInfo? _MyRecord; + public WorksheetRowTypeInfo MyRecord => _MyRecord + ??= WorksheetRowMetadataServices.CreateObjectInfo( AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) @@ -40,7 +40,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre } } - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithSingleProperty? obj, CancellationToken token) + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyRecord? obj, CancellationToken token) { if (spreadsheet is null) throw new ArgumentNullException(nameof(spreadsheet)); @@ -50,7 +50,7 @@ private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, Sp } private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { if (spreadsheet is null) @@ -61,7 +61,7 @@ private static ValueTask AddRangeAsRowsAsync(SpreadCheetah.Spreadsheet spreadshe } private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithSingleProperty obj, + MyNamespace.MyRecord obj, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -77,7 +77,7 @@ private static async ValueTask AddAsRowInternalAsync(SpreadCheetah.Spreadsheet s } private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreadsheet spreadsheet, - IEnumerable objs, + IEnumerable objs, CancellationToken token) { var cells = ArrayPool.Shared.Rent(1); @@ -96,7 +96,7 @@ private static async ValueTask AddRangeAsRowsInternalAsync(SpreadCheetah.Spreads } private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithSingleProperty? obj, + MyNamespace.MyRecord? obj, DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) { if (obj is null) diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_RecordStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_RecordStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs new file mode 100644 index 00000000..bf03bb83 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_RecordStructWithSingleProperty#MyNamespace.MyContext.g.verified.cs @@ -0,0 +1,111 @@ +//HintName: MyNamespace.MyContext.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 MyContext + { + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); + + public MyContext() + { + } + + private WorksheetRowTypeInfo? _MyRecordStruct; + public WorksheetRowTypeInfo MyRecordStruct => _MyRecordStruct + ??= WorksheetRowMetadataServices.CreateObjectInfo( + AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); + + private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + cells[0] = new StyledCell("Value", styleId); + await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); + } + finally + { + ArrayPool.Shared.Return(cells, true); + } + } + + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyRecordStruct obj, CancellationToken token) + { + if (spreadsheet is null) + throw new ArgumentNullException(nameof(spreadsheet)); + 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.MyRecordStruct obj, + CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + var styleIds = Array.Empty(); + 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(1); + try + { + var styleIds = Array.Empty(); + 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.MyRecordStruct obj, + DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) + { + cells[0] = new DataCell(obj.Value); + 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.RowType_StructWithSingleProperty#MyNamespace.MyContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_StructWithSingleProperty#MyNamespace.MyContext.g.verified.cs new file mode 100644 index 00000000..de48135b --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.RowType_StructWithSingleProperty#MyNamespace.MyContext.g.verified.cs @@ -0,0 +1,111 @@ +//HintName: MyNamespace.MyContext.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 MyContext + { + private static MyContext? _default; + public static MyContext Default => _default ??= new MyContext(); + + public MyContext() + { + } + + private WorksheetRowTypeInfo? _MyStruct; + public WorksheetRowTypeInfo MyStruct => _MyStruct + ??= WorksheetRowMetadataServices.CreateObjectInfo( + AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); + + private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + cells[0] = new StyledCell("Id", styleId); + await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); + } + finally + { + ArrayPool.Shared.Return(cells, true); + } + } + + private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, MyNamespace.MyStruct obj, CancellationToken token) + { + if (spreadsheet is null) + throw new ArgumentNullException(nameof(spreadsheet)); + 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.MyStruct obj, + CancellationToken token) + { + var cells = ArrayPool.Shared.Rent(1); + try + { + var styleIds = Array.Empty(); + 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(1); + try + { + var styleIds = Array.Empty(); + 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.MyStruct obj, + DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) + { + cells[0] = new DataCell(obj.Id); + 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.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateOnInvalidType.verified.txt deleted file mode 100644 index 29eda5b5..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateOnInvalidType.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (6,5)-(6,26), - Message: CellValueTruncateAttribute is not supported on properties of type 'int', - Severity: Error, - Descriptor: { - Id: SPCH1005, - Title: Unsupported type for attribute, - MessageFormat: {0} is not supported on properties of type '{1}', - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength.verified.txt deleted file mode 100644 index 79c03f87..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (6,5)-(6,25), - Message: '0' is an invalid argument for CellValueTruncateAttribute, - Severity: Error, - Descriptor: { - Id: SPCH1006, - Title: Invalid attribute argument, - MessageFormat: '{0}' is an invalid argument for {1}, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth.verified.txt deleted file mode 100644 index fdc15082..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (6,5)-(6,21), - Message: '300' is an invalid argument for ColumnWidthAttribute, - Severity: Error, - Descriptor: { - Id: SPCH1006, - Title: Invalid attribute argument, - MessageFormat: '{0}' is an invalid argument for {1}, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering.verified.txt deleted file mode 100644 index d00e9d5d..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (8,5)-(8,19), - Message: The type 'ClassWithDuplicateColumnOrdering' has two or more properties with the same column order, - Severity: Error, - Descriptor: { - Id: SPCH1003, - Title: Duplicate column ordering, - MessageFormat: The type '{0}' has two or more properties with the same column order, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance.verified.txt deleted file mode 100644 index 9cd4912a..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance.verified.txt +++ /dev/null @@ -1,17 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (7,5)-(7,19), - Message: The type 'ClassWithDuplicateColumnOrdering' has two or more properties with the same column order, - Severity: Error, - Descriptor: { - Id: SPCH1003, - Title: Duplicate column ordering, - MessageFormat: The type '{0}' has two or more properties with the same column order, - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file 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 deleted file mode 100644 index c9994b71..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//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? _ClassWithInheritance; - public WorksheetRowTypeInfo ClassWithInheritance => _ClassWithInheritance - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.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.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - var styleIds = Array.Empty(); - 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 styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithInheritance? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Address); - 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.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInvalidPropertyReferenceColumnHeaders.verified.txt deleted file mode 100644 index e7128f80..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithInvalidPropertyReferenceColumnHeaders.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (16,5)-(16,63), - Message: 'NonExistingProperty' on type 'MyNamespace.ColumnHeaders' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Severity: Error, - Descriptor: { - Id: SPCH1004, - Title: Invalid ColumnHeader property reference, - MessageFormat: '{0}' on type '{1}' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - }, - { - Location: : (18,5)-(18,48), - Message: 'name' on type 'MyNamespace.ColumnHeaders' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Severity: Error, - Descriptor: { - Id: SPCH1004, - Title: Invalid ColumnHeader property reference, - MessageFormat: '{0}' on type '{1}' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - }, - { - Location: : (20,5)-(20,85), - Message: 'PrivateGetterProperty' on type 'MyNamespace.ColumnHeaders' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Severity: Error, - Descriptor: { - Id: SPCH1004, - Title: Invalid ColumnHeader property reference, - MessageFormat: '{0}' on type '{1}' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - }, - { - Location: : (22,5)-(22,81), - Message: 'WriteOnlyProperty' on type 'MyNamespace.ColumnHeaders' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Severity: Error, - Descriptor: { - Id: SPCH1004, - Title: Invalid ColumnHeader property reference, - MessageFormat: '{0}' on type '{1}' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - }, - { - Location: : (24,5)-(24,81), - Message: 'NonStringProperty' on type 'MyNamespace.ColumnHeaders' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Severity: Error, - Descriptor: { - Id: SPCH1004, - Title: Invalid ColumnHeader property reference, - MessageFormat: '{0}' on type '{1}' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - }, - { - Location: : (26,5)-(26,80), - Message: 'InternalProperty' on type 'MyNamespace.ColumnHeaders' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Severity: Error, - Descriptor: { - Id: SPCH1004, - Title: Invalid ColumnHeader property reference, - MessageFormat: '{0}' on type '{1}' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - }, - { - Location: : (28,5)-(28,81), - Message: 'NonStaticProperty' on type 'MyNamespace.ColumnHeaders' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Severity: Error, - Descriptor: { - Id: SPCH1004, - Title: Invalid ColumnHeader property reference, - MessageFormat: '{0}' on type '{1}' is not a valid property reference. It must be a static property, have a public getter, and the return type must be a string (or string?)., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Error, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithMultipleProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithMultipleProperties#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 2dc33253..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithMultipleProperties#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,126 +0,0 @@ -//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? _ClassWithMultipleProperties; - public WorksheetRowTypeInfo ClassWithMultipleProperties => _ClassWithMultipleProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.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.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(6); - try - { - var styleIds = Array.Empty(); - 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(6); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.FirstName); - cells[1] = new DataCell(obj.MiddleName); - cells[2] = new DataCell(obj.LastName); - cells[3] = new DataCell(obj.Age); - cells[4] = new DataCell(obj.Employed); - 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_ClassWithNoProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithNoProperties#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index b698df08..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithNoProperties#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,35 +0,0 @@ -//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? _ClassWithNoProperties; - public WorksheetRowTypeInfo ClassWithNoProperties => _ClassWithNoProperties - ??= EmptyWorksheetRowContext.CreateTypeInfo(); - - 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_ClassWithNoProperties.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithNoProperties.verified.txt deleted file mode 100644 index 5ed68787..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithNoProperties.verified.txt +++ /dev/null @@ -1,18 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (6,5)-(6,48), - Message: The type 'ClassWithNoProperties' has no properties with public getters. This will cause an empty row to be added., - Severity: Warning, - WarningLevel: 1, - Descriptor: { - Id: SPCH1001, - Title: Missing properties with public getters, - MessageFormat: The type '{0}' has no properties with public getters. This will cause an empty row to be added., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Warning, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithNoPropertiesAndWarningsSuppressed#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithNoPropertiesAndWarningsSuppressed#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index f1c32a66..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithNoPropertiesAndWarningsSuppressed#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,35 +0,0 @@ -//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? _ClassWithNoProperties; - public WorksheetRowTypeInfo ClassWithNoProperties => _ClassWithNoProperties - ??= EmptyWorksheetRowContext.CreateTypeInfo(); - - 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_ClassWithUnsupportedProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithUnsupportedProperty#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 4af6041f..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithUnsupportedProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,116 +0,0 @@ -//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? _ClassWithUnsupportedProperty; - public WorksheetRowTypeInfo ClassWithUnsupportedProperty => _ClassWithUnsupportedProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - cells[0] = new StyledCell("Name", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - var styleIds = Array.Empty(); - 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(1); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - 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_ClassWithUnsupportedProperty.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithUnsupportedProperty.verified.txt deleted file mode 100644 index 1d1a59a2..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithUnsupportedProperty.verified.txt +++ /dev/null @@ -1,18 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (6,5)-(6,55), - Message: The type 'ClassWithUnsupportedProperty' has a property of type 'Uri' which is not supported as a cell value. The property will be ignored when creating the row., - Severity: Warning, - WarningLevel: 1, - Descriptor: { - Id: SPCH1002, - Title: Unsupported type for cell value, - MessageFormat: The type '{0}' has a property of type '{1}' which is not supported as a cell value. The property will be ignored when creating the row., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Warning, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithUnsupportedPropertyAndWarningsSuppressed#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithUnsupportedPropertyAndWarningsSuppressed#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 3eab26a9..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ClassWithUnsupportedPropertyAndWarningsSuppressed#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,116 +0,0 @@ -//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? _ClassWithUnsupportedProperty; - public WorksheetRowTypeInfo ClassWithUnsupportedProperty => _ClassWithUnsupportedProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - cells[0] = new StyledCell("Name", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - var styleIds = Array.Empty(); - 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(1); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithUnsupportedProperty? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - 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_ContextClassWithDefaultAccessibility#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextClassWithDefaultAccessibility#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 84581cf2..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextClassWithDefaultAccessibility#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,116 +0,0 @@ -//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 -{ - internal partial class MyGenRowContext - { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); - - public MyGenRowContext() - { - } - - private WorksheetRowTypeInfo? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - cells[0] = new StyledCell("Name", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); - } - finally - { - ArrayPool.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.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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - var styleIds = Array.Empty(); - 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(1); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - 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_ContextClassWithInternalAccessibility#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextClassWithInternalAccessibility#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 84581cf2..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextClassWithInternalAccessibility#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,116 +0,0 @@ -//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 -{ - internal partial class MyGenRowContext - { - private static MyGenRowContext? _default; - public static MyGenRowContext Default => _default ??= new MyGenRowContext(); - - public MyGenRowContext() - { - } - - private WorksheetRowTypeInfo? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - cells[0] = new StyledCell("Name", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); - } - finally - { - ArrayPool.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.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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - var styleIds = Array.Empty(); - 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(1); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - 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_ContextWithTwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning.verified.txt b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning.verified.txt deleted file mode 100644 index 9d6c17e0..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning.verified.txt +++ /dev/null @@ -1,18 +0,0 @@ -{ - Diagnostics: [ - { - Location: : (6,1)-(6,51), - Message: The type 'ClassWithUnsupportedProperty' has a property of type 'Uri' which is not supported as a cell value. The property will be ignored when creating the row., - Severity: Warning, - WarningLevel: 1, - Descriptor: { - Id: SPCH1002, - Title: Unsupported type for cell value, - MessageFormat: The type '{0}' has a property of type '{1}' which is not supported as a cell value. The property will be ignored when creating the row., - Category: SpreadCheetah.SourceGenerator, - DefaultSeverity: Warning, - IsEnabledByDefault: true - } - } - ] -} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ReadOnlyRecordStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ReadOnlyRecordStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 4e253b91..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_ReadOnlyRecordStructWithSingleProperty#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,111 +0,0 @@ -//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? _ReadOnlyRecordStructWithSingleProperty; - public WorksheetRowTypeInfo ReadOnlyRecordStructWithSingleProperty => _ReadOnlyRecordStructWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - cells[0] = new StyledCell("Value", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ReadOnlyRecordStructWithSingleProperty obj, CancellationToken token) - { - if (spreadsheet is null) - throw new ArgumentNullException(nameof(spreadsheet)); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ReadOnlyRecordStructWithSingleProperty obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - var styleIds = Array.Empty(); - 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(1); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ReadOnlyRecordStructWithSingleProperty obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - cells[0] = new DataCell(obj.Value); - 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_RecordClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index c29dffb2..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,104 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs -// -#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? _RecordClassWithInheritance; - public WorksheetRowTypeInfo RecordClassWithInheritance => _RecordClassWithInheritance - ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - cells[0] = new StyledCell("Name", styleId); - cells[1] = new StyledCell("Age", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritance? 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritance obj, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - await AddCellsAsRowAsync(spreadsheet, obj, cells, 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 - { - await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - 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.RecordClassWithInheritance? obj, DataCell[] cells, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Name); - cells[1] = new DataCell(obj.Age); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token); - } - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndInheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndInheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 6dd993d3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndInheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,106 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs -// -#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? _RecordClassWithInheritanceAndStartFromInheritedProperties; - public WorksheetRowTypeInfo RecordClassWithInheritanceAndStartFromInheritedProperties => _RecordClassWithInheritanceAndStartFromInheritedProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("Value", styleId); - cells[1] = new StyledCell("Name", styleId); - cells[2] = new StyledCell("Age", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromInheritedProperties? 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromInheritedProperties obj, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - await AddCellsAsRowAsync(spreadsheet, obj, cells, 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(3); - try - { - await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - 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.RecordClassWithInheritanceAndStartFromInheritedProperties? obj, DataCell[] cells, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Value); - cells[1] = new DataCell(obj.Name); - cells[2] = new DataCell(obj.Age); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token); - } - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndInheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndInheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index a8d2b7be..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndInheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,106 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs -// -#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? _RecordClassWithInheritanceAndStartFromClassProperties; - public WorksheetRowTypeInfo RecordClassWithInheritanceAndStartFromClassProperties => _RecordClassWithInheritanceAndStartFromClassProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("Name", styleId); - cells[1] = new StyledCell("Age", styleId); - cells[2] = new StyledCell("Value", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromClassProperties? 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromClassProperties obj, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - await AddCellsAsRowAsync(spreadsheet, obj, cells, 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(3); - try - { - await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - 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.RecordClassWithInheritanceAndStartFromClassProperties? obj, DataCell[] cells, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Name); - cells[1] = new DataCell(obj.Age); - cells[2] = new DataCell(obj.Value); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token); - } - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromBaseClassInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromBaseClassInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 6dd993d3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromBaseClassInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,106 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs -// -#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? _RecordClassWithInheritanceAndStartFromInheritedProperties; - public WorksheetRowTypeInfo RecordClassWithInheritanceAndStartFromInheritedProperties => _RecordClassWithInheritanceAndStartFromInheritedProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("Value", styleId); - cells[1] = new StyledCell("Name", styleId); - cells[2] = new StyledCell("Age", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromInheritedProperties? 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromInheritedProperties obj, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - await AddCellsAsRowAsync(spreadsheet, obj, cells, 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(3); - try - { - await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - 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.RecordClassWithInheritanceAndStartFromInheritedProperties? obj, DataCell[] cells, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Value); - cells[1] = new DataCell(obj.Name); - cells[2] = new DataCell(obj.Age); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token); - } - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromClassProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromClassProperties#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index a8d2b7be..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromClassProperties#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,106 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs -// -#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? _RecordClassWithInheritanceAndStartFromClassProperties; - public WorksheetRowTypeInfo RecordClassWithInheritanceAndStartFromClassProperties => _RecordClassWithInheritanceAndStartFromClassProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("Name", styleId); - cells[1] = new StyledCell("Age", styleId); - cells[2] = new StyledCell("Value", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromClassProperties? 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromClassProperties obj, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - await AddCellsAsRowAsync(spreadsheet, obj, cells, 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(3); - try - { - await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - 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.RecordClassWithInheritanceAndStartFromClassProperties? obj, DataCell[] cells, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Name); - cells[1] = new DataCell(obj.Age); - cells[2] = new DataCell(obj.Value); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token); - } - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromInheritedProperties#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromInheritedProperties#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 6dd993d3..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithStartFromInheritedProperties#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,106 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs -// -#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? _RecordClassWithInheritanceAndStartFromInheritedProperties; - public WorksheetRowTypeInfo RecordClassWithInheritanceAndStartFromInheritedProperties => _RecordClassWithInheritanceAndStartFromInheritedProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("Value", styleId); - cells[1] = new StyledCell("Name", styleId); - cells[2] = new StyledCell("Age", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromInheritedProperties? 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritanceAndStartFromInheritedProperties obj, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - await AddCellsAsRowAsync(spreadsheet, obj, cells, 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(3); - try - { - await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - 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.RecordClassWithInheritanceAndStartFromInheritedProperties? obj, DataCell[] cells, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Value); - cells[1] = new DataCell(obj.Name); - cells[2] = new DataCell(obj.Age); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token); - } - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithoutInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithoutInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index c29dffb2..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritanceAndWithoutInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,104 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext.g.cs -// -#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? _RecordClassWithInheritance; - public WorksheetRowTypeInfo RecordClassWithInheritance => _RecordClassWithInheritance - ??= WorksheetRowMetadataServices.CreateObjectInfo(AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - cells[0] = new StyledCell("Name", styleId); - cells[1] = new StyledCell("Age", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritance? 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, SpreadCheetah.SourceGenerator.SnapshotTest.Models.RecordClassWithInheritance obj, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - await AddCellsAsRowAsync(spreadsheet, obj, cells, 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 - { - await AddEnumerableAsRowsAsync(spreadsheet, objs, cells, token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - 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.RecordClassWithInheritance? obj, DataCell[] cells, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Name); - cells[1] = new DataCell(obj.Age); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token); - } - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance_InheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance_InheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 47c5fa44..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance_InheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//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? _RecordClassWithInheritedColumnsFirst; - public WorksheetRowTypeInfo RecordClassWithInheritedColumnsFirst => _RecordClassWithInheritedColumnsFirst - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - cells[0] = new StyledCell("Value", styleId); - cells[1] = new StyledCell("ClassProperty", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithInheritedColumnsFirst? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithInheritedColumnsFirst obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - var styleIds = Array.Empty(); - 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 styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithInheritedColumnsFirst? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Value); - cells[1] = new DataCell(obj.ClassProperty); - 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_RecordClassWithInheritance_InheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance_InheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 6c1d90aa..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance_InheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//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? _RecordClassWithInheritedColumnsLast; - public WorksheetRowTypeInfo RecordClassWithInheritedColumnsLast => _RecordClassWithInheritedColumnsLast - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - cells[0] = new StyledCell("ClassValue", styleId); - cells[1] = new StyledCell("Value", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithInheritedColumnsLast? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithInheritedColumnsLast obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - var styleIds = Array.Empty(); - 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 styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithInheritedColumnsLast? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.ClassValue); - cells[1] = new DataCell(obj.Value); - 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_RecordClassWithInheritance_WithoutInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance_WithoutInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index f301a6d0..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWithInheritance_WithoutInheritanceAttribute#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//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? _RecordClassWithIgnoreInheritance; - public WorksheetRowTypeInfo RecordClassWithIgnoreInheritance => _RecordClassWithIgnoreInheritance - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - cells[0] = new StyledCell("Name", styleId); - cells[1] = new StyledCell("Age", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithIgnoreInheritance? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithIgnoreInheritance obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(2); - try - { - var styleIds = Array.Empty(); - 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 styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClassWithIgnoreInheritance? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Name); - cells[1] = new DataCell(obj.Age); - 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_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 8a20cd7d..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,120 +0,0 @@ -//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? _RecordClass2LevelOfInheritanceInheritedColumnsFirst; - public WorksheetRowTypeInfo RecordClass2LevelOfInheritanceInheritedColumnsFirst => _RecordClass2LevelOfInheritanceInheritedColumnsFirst - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("Value", styleId); - cells[1] = new StyledCell("ClassProperty", styleId); - cells[2] = new StyledCell("OwnProperty", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirst? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirst obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - var styleIds = Array.Empty(); - 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(3); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirst? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Value); - cells[1] = new DataCell(obj.ClassProperty); - cells[2] = new DataCell(obj.OwnProperty); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), 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_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst_ParentIgnore_Inheritance#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst_ParentIgnore_Inheritance#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 6952ad1b..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst_ParentIgnore_Inheritance#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,120 +0,0 @@ -//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? _RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance; - public WorksheetRowTypeInfo RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance => _RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("Name", styleId); - cells[1] = new StyledCell("Age", styleId); - cells[2] = new StyledCell("ClassProperty", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - var styleIds = Array.Empty(); - 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(3); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.Name); - cells[1] = new DataCell(obj.Age); - cells[2] = new DataCell(obj.ClassProperty); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), 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_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index ae4aebd2..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,120 +0,0 @@ -//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? _RecordClass2LevelOfInheritanceInheritedColumnsLast; - public WorksheetRowTypeInfo RecordClass2LevelOfInheritanceInheritedColumnsLast => _RecordClass2LevelOfInheritanceInheritedColumnsLast - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("OwnProperty", styleId); - cells[1] = new StyledCell("Value", styleId); - cells[2] = new StyledCell("ClassProperty", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLast? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLast obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - var styleIds = Array.Empty(); - 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(3); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLast? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.OwnProperty); - cells[1] = new DataCell(obj.Value); - cells[2] = new DataCell(obj.ClassProperty); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), 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_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentIgnore_Inheritance#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentIgnore_Inheritance#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 08ad549b..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentIgnore_Inheritance#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,120 +0,0 @@ -//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? _RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance; - public WorksheetRowTypeInfo RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance => _RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("ClassProperty", styleId); - cells[1] = new StyledCell("Name", styleId); - cells[2] = new StyledCell("Age", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - var styleIds = Array.Empty(); - 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(3); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.ClassProperty); - cells[1] = new DataCell(obj.Name); - cells[2] = new DataCell(obj.Age); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), 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_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index ebd4b605..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsFirst#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,120 +0,0 @@ -//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? _RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst; - public WorksheetRowTypeInfo RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst => _RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("OwnValue", styleId); - cells[1] = new StyledCell("ClassValue", styleId); - cells[2] = new StyledCell("Value", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - var styleIds = Array.Empty(); - 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(3); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.OwnValue); - cells[1] = new DataCell(obj.ClassValue); - cells[2] = new DataCell(obj.Value); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), 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_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 28e5c680..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsLast#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,120 +0,0 @@ -//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? _RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast; - public WorksheetRowTypeInfo RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast => _RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - cells[0] = new StyledCell("ClassValue", styleId); - cells[1] = new StyledCell("Value", styleId); - cells[2] = new StyledCell("OwnValue", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(3); - try - { - var styleIds = Array.Empty(); - 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(3); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns.RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.ClassValue); - cells[1] = new DataCell(obj.Value); - cells[2] = new DataCell(obj.OwnValue); - return spreadsheet.AddRowAsync(cells.AsMemory(0, 3), 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_TwoContextClasses#MyNamespace.MyGenRowContext.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_TwoContextClasses#MyNamespace.MyGenRowContext.g.verified.cs deleted file mode 100644 index 5a902b08..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_TwoContextClasses#MyNamespace.MyGenRowContext.g.verified.cs +++ /dev/null @@ -1,116 +0,0 @@ -//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? _ClassWithSingleProperty; - public WorksheetRowTypeInfo ClassWithSingleProperty => _ClassWithSingleProperty - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - cells[0] = new StyledCell("Name", styleId); - await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false); - } - finally - { - ArrayPool.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.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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(1); - try - { - var styleIds = Array.Empty(); - 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(1); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - 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_TwoContextClasses#MyNamespace.MyGenRowContext2.g.verified.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_TwoContextClasses#MyNamespace.MyGenRowContext2.g.verified.cs deleted file mode 100644 index 15e1f152..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Snapshots/G.WorksheetRowGenerator_Generate_TwoContextClasses#MyNamespace.MyGenRowContext2.g.verified.cs +++ /dev/null @@ -1,126 +0,0 @@ -//HintName: MyNamespace.MyGenRowContext2.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 MyGenRowContext2 - { - private static MyGenRowContext2? _default; - public static MyGenRowContext2 Default => _default ??= new MyGenRowContext2(); - - public MyGenRowContext2() - { - } - - private WorksheetRowTypeInfo? _ClassWithMultipleProperties; - public WorksheetRowTypeInfo ClassWithMultipleProperties => _ClassWithMultipleProperties - ??= WorksheetRowMetadataServices.CreateObjectInfo( - AddHeaderRow0Async, AddAsRowAsync, AddRangeAsRowsAsync, null); - - private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token) - { - var cells = ArrayPool.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.Shared.Return(cells, true); - } - } - - private static ValueTask AddAsRowAsync(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties? 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties obj, - CancellationToken token) - { - var cells = ArrayPool.Shared.Rent(6); - try - { - var styleIds = Array.Empty(); - 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(6); - try - { - var styleIds = Array.Empty(); - 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, - SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithMultipleProperties? obj, - DataCell[] cells, IReadOnlyList styleIds, CancellationToken token) - { - if (obj is null) - return spreadsheet.AddRowAsync(ReadOnlyMemory.Empty, token); - - cells[0] = new DataCell(obj.FirstName); - cells[1] = new DataCell(obj.MiddleName); - cells[2] = new DataCell(obj.LastName); - cells[3] = new DataCell(obj.Age); - cells[4] = new DataCell(obj.Employed); - 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/SpreadCheetah.SourceGenerator.SnapshotTest.csproj b/SpreadCheetah.SourceGenerator.SnapshotTest/SpreadCheetah.SourceGenerator.SnapshotTest.csproj index 7ac7351e..2a4c6376 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/SpreadCheetah.SourceGenerator.SnapshotTest.csproj +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/SpreadCheetah.SourceGenerator.SnapshotTest.csproj @@ -11,6 +11,7 @@ all + diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CachingTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CachingTests.cs new file mode 100644 index 00000000..1b7c3e65 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CachingTests.cs @@ -0,0 +1,36 @@ +using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; +using SpreadCheetah.SourceGenerators; + +namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; + +public class CachingTests +{ + [Fact] + public Task Caching_IncrementalSourceGeneratorCachingCorrectly() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + using System; + + namespace MyNamespace; + + public record MyRecord(string? Name); + + [WorksheetRow(typeof(MyRecord))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act + var (diagnostics, output) = TestHelper.GetGeneratedTrees(source, ["Transform"]); + + // Assert + Assert.Empty(diagnostics); + var outputSource = Assert.Single(output); + + var settings = new VerifySettings(); + settings.UseDirectory("../Snapshots"); + settings.UseTypeName("G"); + return Verify(outputSource, settings); + } +} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellStyleTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellStyleTests.cs index fed675ef..4f54d65a 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellStyleTests.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellStyleTests.cs @@ -81,22 +81,20 @@ public partial class MyGenRowContext : WorksheetRowContext; public Task CellStyle_ClassWithEmptyCellStyle() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ using SpreadCheetah.SourceGeneration; - + namespace MyNamespace; - + public class ClassWithCellStyle { - [CellStyle("")] + [CellStyle({|SPCH1006:""|})] public string? FirstName { get; set; } } - - [WorksheetRow(typeof(ClassWithCellStyle))] - public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } } diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellValueConverterTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellValueConverterTests.cs index fa3d14e9..4d459c67 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellValueConverterTests.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellValueConverterTests.cs @@ -90,19 +90,21 @@ public partial class MyGenRowContext : WorksheetRowContext; public Task CellValueConverter_ClassWithInvalidConverter() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah; using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassWithInvalidConverter { - [CellValueConverter(typeof(DecimalValueConverter))] + [CellValueConverter({|SPCH1007:typeof(DecimalValueConverter)|})] public string? Property { get; set; } } internal class DecimalValueConverter : CellValueConverter { - public override DataCell ConvertToCell(decimal value) => new(value); + public override DataCell ConvertToDataCell(decimal value) => new(value); } [WorksheetRow(typeof(ClassWithInvalidConverter))] @@ -110,7 +112,7 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } [Fact] @@ -151,19 +153,21 @@ public partial class MyGenRowContext : WorksheetRowContext; public Task CellValueConverter_ClassWithConverterThatDoesNotInheritCellValueConverter() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah; using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassWithConverterThatDoesNotInheritCellValueConverter { - [CellValueConverter(typeof(DecimalValueConverter))] + [CellValueConverter({|SPCH1007:typeof(DecimalValueConverter)|})] public decimal Property { get; set; } } internal class DecimalValueConverter { - public override DataCell ConvertToCell(decimal value) => new(value); + public DataCell ConvertToDataCell(decimal value) => new(value); } [WorksheetRow(typeof(ClassWithConverterThatDoesNotInheritCellValueConverter))] @@ -171,7 +175,7 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } [Fact] @@ -206,20 +210,22 @@ public partial class MyGenRowContext : WorksheetRowContext; public Task CellValueConverter_ClassPropertyWithConverterAndCellValueTruncate() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah; using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassPropertyWithConverterAndCellValueTruncate { [CellValueConverter(typeof(StringValueConverter))] - [CellValueTruncate(20)] + [{|SPCH1008:CellValueTruncate(20)|}] public string? Property { get; set; } } internal class StringValueConverter : CellValueConverter { - public override DataCell ConvertToCell(string value) => new(value); + public override DataCell ConvertToDataCell(string value) => new(value); } [WorksheetRow(typeof(ClassPropertyWithConverterAndCellValueTruncate))] @@ -227,26 +233,28 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } [Fact] public Task CellValueConverter_ClassWithoutParameterlessConstructor() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah; using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassWithoutParameterlessConstructor { - [CellValueConverter(typeof(FixedValueConverter))] + [CellValueConverter({|SPCH1009:typeof(FixedValueConverter)|})] public string? Value { get; set; } } internal class FixedValueConverter(string fixedValue) : CellValueConverter { - public override DataCell ConvertToCell(string value) => new(fixedValue); + public override DataCell ConvertToDataCell(string value) => new(fixedValue); } [WorksheetRow(typeof(ClassWithoutParameterlessConstructor))] @@ -254,7 +262,7 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } [Fact] @@ -292,13 +300,15 @@ public partial class MyGenRowContext : WorksheetRowContext; public Task CellValueConverter_ClassWithInvalidConverterOnComplexProperty() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah; using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassWithInvalidConverterOnComplexProperty { - [CellValueConverter(typeof(StringConverter))] + [CellValueConverter({|SPCH1007:typeof(StringConverter)|})] public object? Property1 { get; set; } public string? Property2 { get; set; } @@ -306,7 +316,7 @@ public class ClassWithInvalidConverterOnComplexProperty internal class StringConverter : CellValueConverter { - public override DataCell ConvertToCell(string value) => new(value); + public override DataCell ConvertToDataCell(string value) => new(value); } [WorksheetRow(typeof(ClassWithInvalidConverterOnComplexProperty))] @@ -314,6 +324,6 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source); + return context.RunAsync(); } } \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorCellValueTruncateTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellValueTruncateTests.cs similarity index 77% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorCellValueTruncateTests.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellValueTruncateTests.cs index 01d1d3ba..96b4f804 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorCellValueTruncateTests.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/CellValueTruncateTests.cs @@ -3,10 +3,10 @@ namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; -public class WorksheetRowGeneratorCellValueTruncateTests +public class CellValueTruncateTests { [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithCellValueTruncate() + public Task CellValueTruncate_ClassWithCellValueTruncate() { // Arrange const string source = """ @@ -29,7 +29,7 @@ public partial class MyGenRowContext : WorksheetRowContext; } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithMultipleCellValueTruncate() + public Task CellValueTruncate_ClassWithMultipleCellValueTruncate() { // Arrange const string source = """ @@ -60,17 +60,18 @@ public partial class MyGenRowContext : WorksheetRowContext; } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithCellValueTruncateWithInvalidLength() + public Task CellValueTruncate_ClassWithCellValueTruncateWithInvalidLength() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassWithCellValueTruncate { - [CellValueTruncate(0)] + [CellValueTruncate({|SPCH1006:0|})] public string? Name { get; set; } } @@ -79,21 +80,22 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithCellValueTruncateOnInvalidType() + public Task CellValueTruncate_ClassWithCellValueTruncateOnInvalidType() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassWithCellValueTruncate { - [CellValueTruncate(10)] + [{|SPCH1005:CellValueTruncate(10)|}] public int Year { get; set; } } @@ -102,6 +104,6 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } } diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnHeaderTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnHeaderTests.cs new file mode 100644 index 00000000..e6fbc4b7 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnHeaderTests.cs @@ -0,0 +1,183 @@ +using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; +using SpreadCheetah.SourceGenerators; + +namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; + +public class ColumnHeaderTests +{ + [Fact] + public Task ColumnHeader_ClassWithColumnHeaderForAllProperties() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public class ClassWithColumnHeaderForAllProperties + { + [ColumnHeader("First name")] + public string FirstName { get; set; } = ""; + + [ColumnHeader("Middle name")] + public string? MiddleName { get; set; } + + [ColumnHeader("Last name")] + public string LastName { get; set; } = ""; + + [ColumnHeader("Age")] + public int Age { get; set; } + + [ColumnHeader("Employed (yes/no)")] + public bool Employed { get; set; } + + [ColumnHeader("Score (decimal)")] + public double Score { get; set; } + } + + [WorksheetRow(typeof(ClassWithColumnHeaderForAllProperties))] + public partial class MyGenRowContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task ColumnHeader_ClassWithSpecialCharacterColumnHeaders() + { + // Arrange + const string source = """" + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public class ClassWithSpecialCharacterColumnHeaders + { + [ColumnHeader("First name")] + public string? FirstName { get; set; } + + [ColumnHeader("")] + public string? LastName { get; set; } + + [ColumnHeader("Nationality (escaped characters \", \', \\)")] + public string? Nationality { get; set; } + + [ColumnHeader("Address line 1 (escaped characters \r\n, \t)")] + public string? AddressLine1 { get; set; } + + [ColumnHeader(@"Address line 2 (verbatim + string: "", \)")] + public string? AddressLine2 { get; set; } + + [ColumnHeader(""" + Age ( + raw + string + literal + ) + """)] + public int Age { get; set; } + + [ColumnHeader("Note (unicode escape sequence 🌉, \ud83d\udc4d, \xE7)")] + public string? Note { get; set; } + + private const string Constant = "This is a constant"; + + [ColumnHeader($"Note 2 (constant interpolated string: {Constant})")] + public string? Note2 { get; set; } + } + + [WorksheetRow(typeof(ClassWithSpecialCharacterColumnHeaders))] + public partial class MyGenRowContext : WorksheetRowContext; + """"; + + // Act & Assert + return TestHelper.CompileAndVerify(source, replaceEscapedLineEndings: true); + } + + [Fact] + public Task ColumnHeader_ClassWithPropertyReferenceColumnHeaders() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + using SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader; + + namespace MyNamespace; + + public class ClassWithPropertyReferenceColumnHeaders + { + [ColumnHeader(typeof(ColumnHeaderResources), nameof(ColumnHeaderResources.Header_FirstName))] + public string? FirstName { get; set; } + + [ColumnHeader(propertyName: nameof(ColumnHeaderResources.Header_LastName), type: typeof(ColumnHeaderResources))] + public string? LastName { get; set; } + + [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderNationality))] + public string? Nationality { get; set; } + + [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderAddressLine1))] + public string? AddressLine1 { get; set; } + + [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderAddressLine2))] + public string? AddressLine2 { get; set; } + + [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.HeaderAge))] + public int Age { get; set; } + } + + [WorksheetRow(typeof(ClassWithPropertyReferenceColumnHeaders))] + public partial class MyGenRowContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task ColumnHeader_ClassWithInvalidPropertyReferenceColumnHeaders() + { + // Arrange + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public class ColumnHeaders + { + public static string Name => "The name"; + public static string PrivateGetterProperty { private get; set; } = "Private getter property"; + public static string WriteOnlyProperty { set => _ = value; } + public static int NonStringProperty => 2024; + internal static string InternalProperty => "Internal property"; + public string NonStaticProperty => "Non static property"; + } + + public class ClassWithInvalidPropertyReferenceColumnHeaders + { + [ColumnHeader{|SPCH1004:(typeof(ColumnHeaders), "NonExistingProperty")|}] + public string PropertyA { get; set; } + [ColumnHeader{|SPCH1004:(typeof(ColumnHeaders), "name")|}] + public string PropertyB { get; set; } + [ColumnHeader{|SPCH1004:(typeof(ColumnHeaders), nameof(ColumnHeaders.PrivateGetterProperty))|}] + public string PropertyC { get; set; } + [ColumnHeader{|SPCH1004:(typeof(ColumnHeaders), nameof(ColumnHeaders.WriteOnlyProperty))|}] + public string PropertyD { get; set; } + [ColumnHeader{|SPCH1004:(typeof(ColumnHeaders), nameof(ColumnHeaders.NonStringProperty))|}] + public string PropertyE { get; set; } + [ColumnHeader{|SPCH1004:(typeof(ColumnHeaders), nameof(ColumnHeaders.InternalProperty))|}] + public string PropertyF { get; set; } + [ColumnHeader{|SPCH1004:(typeof(ColumnHeaders), nameof(ColumnHeaders.NonStaticProperty))|}] + public string PropertyG { get; set; } + } + + [WorksheetRow(typeof(ClassWithInvalidPropertyReferenceColumnHeaders))] + public partial class MyGenRowContext : WorksheetRowContext; + """; + + // Act & Assert + return context.RunAsync(); + } +} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnOrderTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnOrderTests.cs similarity index 57% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnOrderTests.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnOrderTests.cs index 8da2759d..322494d3 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnOrderTests.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnOrderTests.cs @@ -3,17 +3,37 @@ namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; -public class WorksheetRowGeneratorColumnOrderTests +public class ColumnOrderTests { [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithColumnOrderForAllProperties() + public Task ColumnOrder_ClassWithColumnOrderForAllProperties() { // Arrange const string source = """ using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering; namespace MyNamespace; + + 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; } + } [WorksheetRow(typeof(ClassWithColumnOrderForAllProperties))] public partial class MyGenRowContext : WorksheetRowContext; @@ -24,14 +44,31 @@ public partial class MyGenRowContext : WorksheetRowContext; } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithColumnOrderForSomeProperties() + public Task ColumnOrder_ClassWithColumnOrderForSomeProperties() { // Arrange const string source = """ using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnOrdering; namespace MyNamespace; + + 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; } + } [WorksheetRow(typeof(ClassWithColumnOrderForSomeProperties))] public partial class MyGenRowContext : WorksheetRowContext; @@ -42,10 +79,11 @@ public partial class MyGenRowContext : WorksheetRowContext; } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrdering() + public Task ColumnOrder_ClassWithDuplicateColumnOrdering() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ using SpreadCheetah.SourceGeneration; namespace MyNamespace; @@ -54,7 +92,7 @@ public class ClassWithDuplicateColumnOrdering { [ColumnOrder(1)] public string PropertyA { get; set; } - [ColumnOrder(1)] + [{|SPCH1003:ColumnOrder(1)|}] public string PropertyB { get; set; } } @@ -63,14 +101,15 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithDuplicateColumnOrderingAcrossInheritance() + public Task ColumnOrder_ClassWithDuplicateColumnOrderingAcrossInheritance() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ using SpreadCheetah.SourceGeneration; namespace MyNamespace; @@ -78,7 +117,7 @@ namespace MyNamespace; [InheritColumns] public class ClassWithDuplicateColumnOrdering : ClassWithDuplicateColumnOrderingBase { - [ColumnOrder(1)] + [{|SPCH1003:ColumnOrder(1)|}] public string PropertyA { get; set; } } @@ -93,6 +132,6 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } } diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnWidthTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnWidthTests.cs similarity index 83% rename from SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnWidthTests.cs rename to SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnWidthTests.cs index e5e87e7a..c81116fe 100644 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnWidthTests.cs +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnWidthTests.cs @@ -3,10 +3,10 @@ namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; -public class WorksheetRowGeneratorColumnWidthTests +public class ColumnWidthTests { [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithColumnWidth() + public Task ColumnWidth_ClassWithColumnWidth() { // Arrange const string source = """ @@ -29,7 +29,7 @@ public partial class MyGenRowContext : WorksheetRowContext; } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithMultipleColumnWidths() + public Task ColumnWidth_ClassWithMultipleColumnWidths() { // Arrange const string source = """ @@ -60,7 +60,7 @@ public partial class MyGenRowContext : WorksheetRowContext; } [Fact] - public Task WorksheetRowGenerator_Generate_ContextWithTwoClassesWithColumnWidth() + public Task ColumnWidth_ContextWithTwoClassesWithColumnWidth() { // Arrange const string source = """ @@ -90,17 +90,18 @@ public partial class MyGenRowContext : WorksheetRowContext; } [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithColumnWidthWithInvalidWidth() + public Task ColumnWidth_ClassWithColumnWidthWithInvalidWidth() { // Arrange - const string source = """ + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ using SpreadCheetah.SourceGeneration; namespace MyNamespace; public class ClassWithColumnWidth { - [ColumnWidth(300)] + [ColumnWidth({|SPCH1006:300|})] public string? Name { get; set; } } @@ -109,6 +110,6 @@ public partial class MyGenRowContext : WorksheetRowContext; """; // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); + return context.RunAsync(); } } diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ContextTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ContextTests.cs new file mode 100644 index 00000000..b04235da --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ContextTests.cs @@ -0,0 +1,140 @@ +using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; +using SpreadCheetah.SourceGenerators; + +namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; + +public class ContextTests +{ + [Fact] + public Task Context_InternalAccessibility() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public record MyRecord(string? Name); + + [WorksheetRow(typeof(MyRecord))] + internal partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task Context_DefaultAccessibility() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public record MyRecord(string? Name); + + [WorksheetRow(typeof(MyRecord))] + partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task Context_TwoWorksheetRowAttributes() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public record RecordA(string? Name); + public record RecordB(int Id); + + [WorksheetRow(typeof(RecordA))] + [WorksheetRow(typeof(RecordB))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task Context_TwoSimilarWorksheetRowAttributes() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace NamespaceA + { + public record MyRecord(string? Name); + } + + namespace NamespaceB + { + public record MyRecord(string? Name); + } + + namespace MyNamespace + { + [WorksheetRow(typeof(NamespaceA.MyRecord))] + [WorksheetRow(typeof(NamespaceB.MyRecord))] + public partial class MyContext : WorksheetRowContext; + } + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task Context_TwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + using System; + + namespace MyNamespace; + + public record RecordA(string? Name, Uri? Uri); + public record RecordB(string? Name); + + [WorksheetRow(typeof(RecordA))] + [WorksheetRow(typeof(RecordB))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task Context_TwoContextClasses() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public record RecordA(string? Name); + public record RecordB(int Id); + + [WorksheetRow(typeof(RecordA))] + public partial class MyContextA : WorksheetRowContext; + + [WorksheetRow(typeof(RecordB))] + public partial class MyContextB : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } +} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/PropertyTypeTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/PropertyTypeTests.cs new file mode 100644 index 00000000..ecde1ce3 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/PropertyTypeTests.cs @@ -0,0 +1,111 @@ +using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; +using SpreadCheetah.SourceGenerators; + +namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; + +public class PropertyTypeTests +{ + [Fact] + public Task PropertyType_ClassWithUnsupportedProperty() + { + // Arrange + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah.SourceGeneration; + using System; + + namespace MyNamespace; + + public record RecordWithUnsupportedProperty(Uri HomepageUri); + + [WorksheetRow({|SPCH1002:typeof(RecordWithUnsupportedProperty)|})] + public partial class MyGenRowContext : WorksheetRowContext; + """; + + // Act & Assert + return context.RunAsync(); + } + + [Fact] + public Task PropertyType_ClassWithUnsupportedPropertyAndWarningsSuppressed() + { + // Arrange + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah.SourceGeneration; + using System; + + namespace MyNamespace; + + public record RecordWithUnsupportedProperty(Uri HomepageUri); + + [WorksheetRow(typeof(RecordWithUnsupportedProperty))] + [WorksheetRowGenerationOptions(SuppressWarnings = true)] + public partial class MyGenRowContext : WorksheetRowContext; + """; + + // Act & Assert + return context.RunAsync(); + } + + [Fact] + public Task PropertyType_ClassWithAllSupportedTypes() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + using System; + + namespace MyNamespace; + + public class ClassWithAllSupportedTypes + { + public string StringValue { get; set; } = ""; + public string? NullableStringValue { get; set; } + public int IntValue { get; set; } + public int? NullableIntValue { get; set; } + public long LongValue { get; set; } + public long? NullableLongValue { get; set; } + public float FloatValue { get; set; } + public float? NullableFloatValue { get; set; } + public double DoubleValue { get; set; } + public double? NullableDoubleValue { get; set; } + public decimal DecimalValue { get; set; } + public decimal? NullableDecimalValue { get; set; } + public DateTime DateTimeValue { get; set; } + public DateTime? NullableDateTimeValue { get; set; } + public bool BoolValue { get; set; } + public bool? NullableBoolValue { get; set; } + } + + [WorksheetRow(typeof(ClassWithAllSupportedTypes))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task PropertyType_ClassWithIndexer() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + using System; + + namespace MyNamespace; + + public class MyClass + { + public int this[int index] => index; + } + + [WorksheetRow(typeof(MyClass))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } +} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/RowTypeTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/RowTypeTests.cs new file mode 100644 index 00000000..40de1e53 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/RowTypeTests.cs @@ -0,0 +1,193 @@ +using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; +using SpreadCheetah.SourceGenerators; + +namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; + +public class RowTypeTests +{ + [Fact] + public Task RowType_ClassWithNoProperties() + { + // Arrange + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public class ClassWithNoProperties; + + [WorksheetRow({|SPCH1001:typeof(ClassWithNoProperties)|})] + public partial class MyGenRowContext : WorksheetRowContext; + """; + + // Act & Assert + return context.RunAsync(); + } + + [Fact] + public Task RowType_ClassWithNoPropertiesAndWarningsSuppressed() + { + // Arrange + var context = AnalyzerTest.CreateContext(); + context.TestCode = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public class ClassWithNoProperties; + + [WorksheetRow(typeof(ClassWithNoProperties))] + [WorksheetRowGenerationOptions(SuppressWarnings = true)] + public partial class MyGenRowContext : WorksheetRowContext; + """; + + // Act & Assert + return context.RunAsync(); + } + + [Fact] + public Task RowType_ClassWithSingleProperty() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public class MyClass + { + public string? Name { get; set; } + } + + [WorksheetRow(typeof(MyClass))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task RowType_InternalClassWithSingleProperty() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + internal class MyInternalClass + { + public string? Name { get; set; } + } + + [WorksheetRow(typeof(MyInternalClass))] + internal partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task RowType_RecordClassWithSingleProperty() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public record MyRecord(bool Value); + + [WorksheetRow(typeof(MyRecord))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task RowType_StructWithSingleProperty() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public struct MyStruct + { + public int Id { get; set; } + } + + [WorksheetRow(typeof(MyStruct))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task RowType_RecordStructWithSingleProperty() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public record struct MyRecordStruct(double Value); + + [WorksheetRow(typeof(MyRecordStruct))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task RowType_ReadOnlyStructWithSingleProperty() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public readonly struct MyReadOnlyStruct + { + public int Value { get; } + } + + [WorksheetRow(typeof(MyReadOnlyStruct))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } + + [Fact] + public Task RowType_ReadOnlyRecordStructWithSingleProperty() + { + // Arrange + const string source = """ + using SpreadCheetah.SourceGeneration; + + namespace MyNamespace; + + public readonly record struct MyReadOnlyRecordStruct(int Value); + + [WorksheetRow(typeof(MyReadOnlyRecordStruct))] + public partial class MyContext : WorksheetRowContext; + """; + + // Act & Assert + return TestHelper.CompileAndVerify(source); + } +} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnHeaderTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnHeaderTests.cs deleted file mode 100644 index 550e895b..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorColumnHeaderTests.cs +++ /dev/null @@ -1,106 +0,0 @@ -using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; -using SpreadCheetah.SourceGenerators; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; - -public class WorksheetRowGeneratorColumnHeaderTests -{ - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithColumnHeaderForAllProperties() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader; - - namespace MyNamespace; - - [WorksheetRow(typeof(ClassWithColumnHeaderForAllProperties))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithSpecialCharacterColumnHeaders() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader; - - namespace MyNamespace; - - [WorksheetRow(typeof(ClassWithSpecialCharacterColumnHeaders))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source, replaceEscapedLineEndings: true); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithPropertyReferenceColumnHeaders() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.ColumnHeader; - - namespace MyNamespace; - - [WorksheetRow(typeof(ClassWithPropertyReferenceColumnHeaders))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithInvalidPropertyReferenceColumnHeaders() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - - namespace MyNamespace; - - public class ColumnHeaders - { - public static string Name => "The name"; - public static string PrivateGetterProperty { private get; set; } = "Private getter property"; - public static string WriteOnlyProperty { set => _ = value; } - public static int NonStringProperty => 2024; - internal static string InternalProperty => "Internal property"; - public string NonStaticProperty => "Non static property"; - } - - public class ClassWithInvalidPropertyReferenceColumnHeaders - { - [ColumnHeader(typeof(ColumnHeaders), "NonExistingProperty")] - public string PropertyA { get; set; } - [ColumnHeader(typeof(ColumnHeaders), "name")] - public string PropertyB { get; set; } - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.PrivateGetterProperty))] - public string PropertyC { get; set; } - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.WriteOnlyProperty))] - public string PropertyD { get; set; } - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.NonStringProperty))] - public string PropertyE { get; set; } - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.InternalProperty))] - public string PropertyF { get; set; } - [ColumnHeader(typeof(ColumnHeaders), nameof(ColumnHeaders.NonStaticProperty))] - public string PropertyG { get; set; } - } - - [WorksheetRow(typeof(ClassWithInvalidPropertyReferenceColumnHeaders))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source, onlyDiagnostics: true); - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorInheritColumnsTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorInheritColumnsTests.cs deleted file mode 100644 index d3335ca1..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorInheritColumnsTests.cs +++ /dev/null @@ -1,159 +0,0 @@ -using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; -using SpreadCheetah.SourceGenerators; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; - -public class WorksheetRowGeneratorInheritColumnsTests -{ - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst_ParentIgnore_Inheritance() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClass2LevelOfInheritanceInheritedColumnsFirstParentIgnoreInheritance))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsFirst() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClass2LevelOfInheritanceInheritedColumnsFirst))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentIgnore_Inheritance() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClass2LevelOfInheritanceInheritedColumnsLastParentIgnoreInheritance))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClass2LevelOfInheritanceInheritedColumnsLast))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWithInheritance_InheritedColumnsFirst() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClassWithInheritedColumnsFirst))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWithInheritance_InheritedColumnsLast() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClassWithInheritedColumnsLast))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsLast() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClass2LevelOfInheritanceInheritedColumnsFirstParentInheritColumnsLast))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWith_2LevelOfInheritance_InheritedColumnsLast_ParentInheritColumnsFirst() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(RecordClass2LevelOfInheritanceInheritedColumnsLastParentInheritColumnsFirst))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } -} diff --git a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorTests.cs b/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorTests.cs deleted file mode 100644 index 7990dcfd..00000000 --- a/SpreadCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorTests.cs +++ /dev/null @@ -1,512 +0,0 @@ -using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; -using SpreadCheetah.SourceGenerators; - -namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; - -public class WorksheetRowGeneratorTests -{ - [Fact] - public Task WorksheetRowGenerator_Generate_CachingCorrectly() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act - var (diagnostics, output) = TestHelper.GetGeneratedTrees(source, ["Transform"]); - - // Assert - Assert.Empty(diagnostics); - var outputSource = Assert.Single(output); - - var settings = new VerifySettings(); - settings.UseDirectory("../Snapshots"); - settings.UseTypeName("G"); - return Verify(outputSource, settings); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithSingleProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_InternalClassWithSingleProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using System; - - namespace MyNamespace - { - internal class InternalClassWithSingleProperty - { - public string? Name { get; set; } - } - - [WorksheetRow(typeof(InternalClassWithSingleProperty))] - internal partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithAllSupportedTypes() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithAllSupportedTypes))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithMultipleProperties() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithMultipleProperties))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithNoProperties() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithNoProperties))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithNoPropertiesAndWarningsSuppressed() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRowGenerationOptions(SuppressWarnings = true)] - [WorksheetRow(typeof(ClassWithNoProperties))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithUnsupportedProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithUnsupportedProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithUnsupportedPropertyAndWarningsSuppressed() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithUnsupportedProperty))] - [WorksheetRowGenerationOptions(SuppressWarnings = true)] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ClassWithInheritance() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithInheritance))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWithSingleProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(RecordClassWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_StructWithSingleProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(StructWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordStructWithSingleProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(RecordStructWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ReadOnlyStructWithSingleProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ReadOnlyStructWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ReadOnlyRecordStructWithSingleProperty() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ReadOnlyRecordStructWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_RecordClassWithInheritance_WithoutInheritanceAttribute() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models.InheritColumns; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(RecordClassWithIgnoreInheritance))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - - - [Fact] - public Task WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributes() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithSingleProperty))] - [WorksheetRow(typeof(ClassWithMultipleProperties))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ContextWithTwoSimilarWorksheetRowAttributes() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(SpreadCheetah.SourceGenerator.SnapshotTest.Models.ClassWithSingleProperty))] - [WorksheetRow(typeof(SpreadCheetah.SourceGenerator.SnapshotTest.AlternativeModels.ClassWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ContextWithTwoWorksheetRowAttributesWhenTheFirstTypeEmitsWarning() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(ClassWithUnsupportedProperty))] - [WorksheetRow(typeof(ClassWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext; - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ContextClassWithInternalAccessibility() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithSingleProperty))] - internal partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_ContextClassWithDefaultAccessibility() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace - { - [WorksheetRow(typeof(ClassWithSingleProperty))] - partial class MyGenRowContext : WorksheetRowContext - { - } - } - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } - - [Fact] - public Task WorksheetRowGenerator_Generate_TwoContextClasses() - { - // Arrange - const string source = """ - using SpreadCheetah.SourceGeneration; - using SpreadCheetah.SourceGenerator.SnapshotTest.Models; - using System; - - namespace MyNamespace; - - [WorksheetRow(typeof(ClassWithSingleProperty))] - public partial class MyGenRowContext : WorksheetRowContext - { - } - - [WorksheetRow(typeof(ClassWithMultipleProperties))] - public partial class MyGenRowContext2 : WorksheetRowContext - { - } - - """; - - // Act & Assert - return TestHelper.CompileAndVerify(source); - } -} diff --git a/SpreadCheetah.SourceGenerator.Test/Models/Contexts/CustomTypeContext.cs b/SpreadCheetah.SourceGenerator.Test/Models/Contexts/CustomTypeContext.cs index 33fac97f..b290e53b 100644 --- a/SpreadCheetah.SourceGenerator.Test/Models/Contexts/CustomTypeContext.cs +++ b/SpreadCheetah.SourceGenerator.Test/Models/Contexts/CustomTypeContext.cs @@ -3,7 +3,4 @@ namespace SpreadCheetah.SourceGenerator.Test.Models.Contexts; [WorksheetRow(typeof(RecordClassWithCustomType))] -[WorksheetRowGenerationOptions(SuppressWarnings = true)] -public partial class CustomTypeContext : WorksheetRowContext -{ -} +public partial class CustomTypeContext : WorksheetRowContext; \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.Test/Models/Contexts/NoPropertiesContext.cs b/SpreadCheetah.SourceGenerator.Test/Models/Contexts/NoPropertiesContext.cs index cba0ddd9..98e55c55 100644 --- a/SpreadCheetah.SourceGenerator.Test/Models/Contexts/NoPropertiesContext.cs +++ b/SpreadCheetah.SourceGenerator.Test/Models/Contexts/NoPropertiesContext.cs @@ -9,7 +9,4 @@ namespace SpreadCheetah.SourceGenerator.Test.Models.Contexts; [WorksheetRow(typeof(RecordStructWithNoProperties))] [WorksheetRow(typeof(ReadOnlyStructWithNoProperties))] [WorksheetRow(typeof(ReadOnlyRecordStructWithNoProperties))] -[WorksheetRowGenerationOptions(SuppressWarnings = true)] -public partial class NoPropertiesContext : WorksheetRowContext -{ -} +public partial class NoPropertiesContext : WorksheetRowContext; \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/BaseClass.cs b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/BaseClass.cs new file mode 100644 index 00000000..0854e4bd --- /dev/null +++ b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/BaseClass.cs @@ -0,0 +1,6 @@ +namespace SpreadCheetah.SourceGenerator.Test.Models.InheritColumns; + +public class BaseClass +{ + public string? BaseClassProperty { get; set; } +} diff --git a/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/ClassWithInheritedColumnsFirst.cs b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/ClassWithInheritedColumnsFirst.cs new file mode 100644 index 00000000..90227909 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/ClassWithInheritedColumnsFirst.cs @@ -0,0 +1,9 @@ +using SpreadCheetah.SourceGeneration; + +namespace SpreadCheetah.SourceGenerator.Test.Models.InheritColumns; + +[InheritColumns] +public class ClassWithInheritedColumnsFirst : BaseClass +{ + public string? DerivedClassProperty { get; set; } +} diff --git a/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/ClassWithInheritedColumnsLast.cs b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/ClassWithInheritedColumnsLast.cs new file mode 100644 index 00000000..96d7db46 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/ClassWithInheritedColumnsLast.cs @@ -0,0 +1,9 @@ +using SpreadCheetah.SourceGeneration; + +namespace SpreadCheetah.SourceGenerator.Test.Models.InheritColumns; + +[InheritColumns(DefaultColumnOrder = InheritedColumnsOrder.InheritedColumnsLast)] +public class ClassWithInheritedColumnsLast : BaseClass +{ + public string? DerivedClassProperty { get; set; } +} diff --git a/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/DerivedClassWithoutInheritColumns.cs b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/DerivedClassWithoutInheritColumns.cs new file mode 100644 index 00000000..bb33cc59 --- /dev/null +++ b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/DerivedClassWithoutInheritColumns.cs @@ -0,0 +1,6 @@ +namespace SpreadCheetah.SourceGenerator.Test.Models.InheritColumns; + +public class DerivedClassWithoutInheritColumns : BaseClass +{ + public string? DerivedClassProperty { get; set; } +} diff --git a/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/InheritColumnsContext.cs b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/InheritColumnsContext.cs new file mode 100644 index 00000000..a2e8c1ad --- /dev/null +++ b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/InheritColumnsContext.cs @@ -0,0 +1,9 @@ +using SpreadCheetah.SourceGeneration; + +namespace SpreadCheetah.SourceGenerator.Test.Models.InheritColumns; + +[WorksheetRow(typeof(ClassWithInheritedColumnsFirst))] +[WorksheetRow(typeof(ClassWithInheritedColumnsLast))] +[WorksheetRow(typeof(DerivedClassWithoutInheritColumns))] +[WorksheetRow(typeof(TwoLevelInheritanceClassWithInheritedColumns))] +public partial class InheritColumnsContext : WorksheetRowContext; \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/TwoLevelInheritanceClassWithInheritedColumns.cs b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/TwoLevelInheritanceClassWithInheritedColumns.cs new file mode 100644 index 00000000..6ff0c14f --- /dev/null +++ b/SpreadCheetah.SourceGenerator.Test/Models/InheritColumns/TwoLevelInheritanceClassWithInheritedColumns.cs @@ -0,0 +1,9 @@ +using SpreadCheetah.SourceGeneration; + +namespace SpreadCheetah.SourceGenerator.Test.Models.InheritColumns; + +[InheritColumns] +public class TwoLevelInheritanceClassWithInheritedColumns : ClassWithInheritedColumnsLast +{ + public string? LeafClassProperty { get; set; } +} diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/InheritColumnsTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/InheritColumnsTests.cs new file mode 100644 index 00000000..0050109c --- /dev/null +++ b/SpreadCheetah.SourceGenerator.Test/Tests/InheritColumnsTests.cs @@ -0,0 +1,98 @@ +using SpreadCheetah.SourceGenerator.Test.Models.InheritColumns; +using SpreadCheetah.TestHelpers.Assertions; +using SpreadCheetah.TestHelpers.Extensions; +using Xunit; + +namespace SpreadCheetah.SourceGenerator.Test.Tests; + +public class InheritColumnsTests +{ + [Fact] + public async Task InheritColumns_DerivedClassWithoutInheritColumns() + { + // Arrange + using var stream = new MemoryStream(); + await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream); + await spreadsheet.StartWorksheetAsync("Sheet"); + var obj = new DerivedClassWithoutInheritColumns + { + BaseClassProperty = "Base", + DerivedClassProperty = "Derived" + }; + + // Act + await spreadsheet.AddAsRowAsync(obj, InheritColumnsContext.Default.DerivedClassWithoutInheritColumns); + await spreadsheet.FinishAsync(); + + // Assert + using var sheet = SpreadsheetAssert.SingleSheet(stream); + Assert.Equal(["Derived"], sheet.Row(1).StringValues()); + } + + [Fact] + public async Task InheritColumns_InheritedColumnsFirst() + { + // Arrange + using var stream = new MemoryStream(); + await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream); + await spreadsheet.StartWorksheetAsync("Sheet"); + var obj = new ClassWithInheritedColumnsFirst + { + BaseClassProperty = "Base", + DerivedClassProperty = "Derived" + }; + + // Act + await spreadsheet.AddAsRowAsync(obj, InheritColumnsContext.Default.ClassWithInheritedColumnsFirst); + await spreadsheet.FinishAsync(); + + // Assert + using var sheet = SpreadsheetAssert.SingleSheet(stream); + Assert.Equal(["Base", "Derived"], sheet.Row(1).StringValues()); + } + + [Fact] + public async Task InheritColumns_InheritedColumnsLast() + { + // Arrange + using var stream = new MemoryStream(); + await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream); + await spreadsheet.StartWorksheetAsync("Sheet"); + var obj = new ClassWithInheritedColumnsLast + { + BaseClassProperty = "Base", + DerivedClassProperty = "Derived" + }; + + // Act + await spreadsheet.AddAsRowAsync(obj, InheritColumnsContext.Default.ClassWithInheritedColumnsLast); + await spreadsheet.FinishAsync(); + + // Assert + using var sheet = SpreadsheetAssert.SingleSheet(stream); + Assert.Equal(["Derived", "Base"], sheet.Row(1).StringValues()); + } + + [Fact] + public async Task InheritColumns_TwoLevelInheritance() + { + // Arrange + using var stream = new MemoryStream(); + await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream); + await spreadsheet.StartWorksheetAsync("Sheet"); + var obj = new TwoLevelInheritanceClassWithInheritedColumns + { + BaseClassProperty = "Base", + DerivedClassProperty = "Derived", + LeafClassProperty = "Leaf" + }; + + // Act + await spreadsheet.AddAsRowAsync(obj, InheritColumnsContext.Default.TwoLevelInheritanceClassWithInheritedColumns); + await spreadsheet.FinishAsync(); + + // Assert + using var sheet = SpreadsheetAssert.SingleSheet(stream); + Assert.Equal(["Derived", "Base", "Leaf"], sheet.Row(1).StringValues()); + } +} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/WorksheetRowGeneratorTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/WorksheetRowGeneratorTests.cs index 65caf2c6..8ca3d198 100644 --- a/SpreadCheetah.SourceGenerator.Test/Tests/WorksheetRowGeneratorTests.cs +++ b/SpreadCheetah.SourceGenerator.Test/Tests/WorksheetRowGeneratorTests.cs @@ -14,6 +14,7 @@ using SpreadCheetah.SourceGenerator.Test.Models.NoProperties; using SpreadCheetah.Styling; using SpreadCheetah.TestHelpers.Assertions; +using SpreadCheetah.TestHelpers.Extensions; using System.Globalization; using Xunit; using OpenXmlCell = DocumentFormat.OpenXml.Spreadsheet.Cell; @@ -385,8 +386,8 @@ public async Task Spreadsheet_AddRangeAsRows_ObjectWithColumnOrdering(ObjectType // Assert using var sheet = SpreadsheetAssert.SingleSheet(stream); - Assert.Equal(values.Select(x => x.LastName), sheet.Column("A").Cells.Select(x => x.StringValue)); - Assert.Equal(values.Select(x => x.FirstName), sheet.Column("B").Cells.Select(x => x.StringValue)); + Assert.Equal(values.Select(x => x.LastName), sheet.Column("A").Cells.StringValues()); + Assert.Equal(values.Select(x => x.FirstName), sheet.Column("B").Cells.StringValues()); Assert.Equal(values.Select(x => x.Age), sheet.Column("C").Cells.Select(x => x.IntValue ?? -1)); Assert.Equal(values.Select(x => x.Gpa), sheet.Column("D").Cells.Select(x => x.DecimalValue ?? -1)); Assert.Equal(3, sheet.RowCount); @@ -682,7 +683,7 @@ public async Task Spreadsheet_AddHeaderRow_SpecialCharacterColumnHeaders() // Assert using var sheet = SpreadsheetAssert.SingleSheet(stream); - Assert.Equal(expectedValues.Select(x => x.ReplaceLineEndings()), sheet.Row(1).Select(x => x.StringValue?.ReplaceLineEndings())); + Assert.Equal(expectedValues.Select(x => x.ReplaceLineEndings()), sheet.Row(1).StringValues().Select(x => x?.ReplaceLineEndings())); } [Fact] @@ -716,7 +717,7 @@ public async Task Spreadsheet_AddHeaderRow_PropertyReferenceColumnHeaders() // Assert using var sheet = SpreadsheetAssert.SingleSheet(stream); - Assert.Equal(expectedValues, sheet.Row(1).Select(x => x.StringValue)); + Assert.Equal(expectedValues, sheet.Row(1).StringValues()); } [Fact] @@ -744,7 +745,7 @@ public async Task Spreadsheet_AddHeaderRow_ObjectWithMultipleColumnAttributes() // Assert using var sheet = SpreadsheetAssert.SingleSheet(stream); - Assert.Equal(expectedValues, sheet.Row(1).Select(x => x.StringValue)); + Assert.Equal(expectedValues, sheet.Row(1).StringValues()); } [Fact] diff --git a/SpreadCheetah.SourceGenerator/Diagnostics.cs b/SpreadCheetah.SourceGenerator/Diagnostics.cs index b8dc6a4e..8ebe3797 100644 --- a/SpreadCheetah.SourceGenerator/Diagnostics.cs +++ b/SpreadCheetah.SourceGenerator/Diagnostics.cs @@ -1,6 +1,5 @@ using Microsoft.CodeAnalysis; -using SpreadCheetah.SourceGenerator.Extensions; -using SpreadCheetah.SourceGenerator.Models; +using System.Collections.Immutable; namespace SpreadCheetah.SourceGenerator; @@ -8,6 +7,19 @@ internal static class Diagnostics { private const string Category = "SpreadCheetah.SourceGenerator"; + public static ImmutableArray AllDescriptors => + [ + NoPropertiesFoundDescriptor, + UnsupportedTypeForCellValueDescriptor, + DuplicateColumnOrderDescriptor, + InvalidColumnHeaderPropertyReferenceDescriptor, + UnsupportedTypeForAttributeDescriptor, + InvalidAttributeArgumentDescriptor, + AttributeTypeArgumentMustInheritDescriptor, + AttributeCombinationNotSupportedDescriptor, + AttributeTypeArgumentMustHaveDefaultConstructorDescriptor + ]; + public static Diagnostic NoPropertiesFound(Location? location, string rowTypeName) => Diagnostic.Create(NoPropertiesFoundDescriptor, location, rowTypeName); @@ -19,30 +31,30 @@ public static Diagnostic NoPropertiesFound(Location? location, string rowTypeNam defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true); - public static Diagnostic UnsupportedTypeForCellValue(Location? location, string rowTypeName, string unsupportedPropertyTypeName) - => Diagnostic.Create(UnsupportedTypeForCellValueDescriptor, location, rowTypeName, unsupportedPropertyTypeName); + public static Diagnostic UnsupportedTypeForCellValue(Location? location, string rowTypeName, string propertyName, string propertyTypeName) + => Diagnostic.Create(UnsupportedTypeForCellValueDescriptor, location, rowTypeName, propertyName, propertyTypeName); private static readonly DiagnosticDescriptor UnsupportedTypeForCellValueDescriptor = new( id: "SPCH1002", title: "Unsupported type for cell value", - messageFormat: "The type '{0}' has a property of type '{1}' which is not supported as a cell value. The property will be ignored when creating the row.", + messageFormat: "The type '{0}' has property '{1}' of type '{2}' which is not supported as a cell value, unless a CellValueConverter is used. Otherwise the property will be ignored.", category: Category, defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true); - public static DiagnosticInfo DuplicateColumnOrder(LocationInfo? location, string className) - => new(DuplicateColumnOrderDescriptor, location, new([className])); + public static Diagnostic DuplicateColumnOrder(Location? location) + => Diagnostic.Create(DuplicateColumnOrderDescriptor, location); private static readonly DiagnosticDescriptor DuplicateColumnOrderDescriptor = new( id: "SPCH1003", title: "Duplicate column ordering", - messageFormat: "The type '{0}' has two or more properties with the same column order", + messageFormat: "The same column order can not be used on two different properties", category: Category, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticInfo InvalidColumnHeaderPropertyReference(LocationInfo? location, string propertyName, string typeFullName) - => new(InvalidColumnHeaderPropertyReferenceDescriptor, location, new([propertyName, typeFullName])); + public static Diagnostic InvalidColumnHeaderPropertyReference(Location? location, string propertyName, string typeFullName) + => Diagnostic.Create(InvalidColumnHeaderPropertyReferenceDescriptor, location, [propertyName, typeFullName]); private static readonly DiagnosticDescriptor InvalidColumnHeaderPropertyReferenceDescriptor = new( id: "SPCH1004", @@ -52,8 +64,8 @@ public static DiagnosticInfo InvalidColumnHeaderPropertyReference(LocationInfo? defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticInfo UnsupportedTypeForAttribute(AttributeData attribute, string typeFullName, CancellationToken token) - => new(UnsupportedTypeForAttributeDescriptor, attribute.GetLocation(token), new([attribute.Name(), typeFullName])); + public static Diagnostic UnsupportedTypeForAttribute(Location? location, string? attributeName, string typeFullName) + => Diagnostic.Create(UnsupportedTypeForAttributeDescriptor, location, [attributeName ?? "Attribute", typeFullName]); private static readonly DiagnosticDescriptor UnsupportedTypeForAttributeDescriptor = new( id: "SPCH1005", @@ -63,19 +75,19 @@ public static DiagnosticInfo UnsupportedTypeForAttribute(AttributeData attribute defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticInfo InvalidAttributeArgument(AttributeData attribute, string attributeArgument, CancellationToken token) - => new(InvalidAttributeArgumentDescriptor, attribute.GetLocation(token), new([attributeArgument, attribute.Name()])); + public static Diagnostic InvalidAttributeArgument(Location? location, string? attributeName) + => Diagnostic.Create(InvalidAttributeArgumentDescriptor, location, [attributeName ?? "attribute"]); private static readonly DiagnosticDescriptor InvalidAttributeArgumentDescriptor = new( id: "SPCH1006", title: "Invalid attribute argument", - messageFormat: "'{0}' is an invalid argument for {1}", + messageFormat: "Invalid argument for {0}", category: Category, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticInfo AttributeTypeArgumentMustInherit(AttributeData attribute, string typeName, string baseClassName, CancellationToken token) - => new(AttributeTypeArgumentMustInheritDescriptor, attribute.GetLocation(token), new([typeName, attribute.Name(), baseClassName])); + public static Diagnostic AttributeTypeArgumentMustInherit(Location? location, string typeName, string? attributeName, string baseClassName) + => Diagnostic.Create(AttributeTypeArgumentMustInheritDescriptor, location, [typeName, attributeName ?? "attribute", baseClassName]); private static readonly DiagnosticDescriptor AttributeTypeArgumentMustInheritDescriptor = new( id: "SPCH1007", @@ -85,27 +97,25 @@ public static DiagnosticInfo AttributeTypeArgumentMustInherit(AttributeData attr defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticInfo AttributeCombinationNotSupported(LocationInfo? location, string attribute1, string attribute2) - => new(AttributeCombinationNotSupportedDescriptor, location, new([attribute1, attribute2])); + public static Diagnostic AttributeCombinationNotSupported(Location? location, string? attribute1, string attribute2) + => Diagnostic.Create(AttributeCombinationNotSupportedDescriptor, location, [attribute1 ?? "attribute", attribute2]); private static readonly DiagnosticDescriptor AttributeCombinationNotSupportedDescriptor = new( id: "SPCH1008", title: "Attribute combination not supported", - messageFormat: "Having both the {0} and the {1} attributes on a property is not supported", + messageFormat: "Having both {0} and {1} on a property is not supported", category: Category, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - public static DiagnosticInfo AttributeTypeArgumentMustHaveDefaultConstructor(AttributeData attribute, string typeName, CancellationToken token) - => new(AttributeTypeArgumentMustHaveDefaultConstructorDescriptor, attribute.GetLocation(token), new([typeName])); + public static Diagnostic AttributeTypeArgumentMustHaveDefaultConstructor(Location? location, string typeName) + => Diagnostic.Create(AttributeTypeArgumentMustHaveDefaultConstructorDescriptor, location, [typeName]); - private static readonly DiagnosticDescriptor AttributeTypeArgumentMustHaveDefaultConstructorDescriptor = new( + public static readonly DiagnosticDescriptor AttributeTypeArgumentMustHaveDefaultConstructorDescriptor = new( id: "SPCH1009", title: "Type must have a public parameterless constructor", messageFormat: "Type '{0}' must have a public parameterless constructor", category: Category, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); - - private static string Name(this AttributeData attribute) => attribute.AttributeClass?.Name ?? ""; } diff --git a/SpreadCheetah.SourceGenerator/Extensions/AttributeDataExtensions.cs b/SpreadCheetah.SourceGenerator/Extensions/AttributeDataExtensions.cs index 55105472..f63083b9 100644 --- a/SpreadCheetah.SourceGenerator/Extensions/AttributeDataExtensions.cs +++ b/SpreadCheetah.SourceGenerator/Extensions/AttributeDataExtensions.cs @@ -1,52 +1,16 @@ using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using SpreadCheetah.SourceGenerator.Helpers; -using SpreadCheetah.SourceGenerator.Models; -using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; -using System.Globalization; namespace SpreadCheetah.SourceGenerator.Extensions; internal static class AttributeDataExtensions { - public static PropertyAttributeData MapToPropertyAttributeData( - this ImmutableArray attributes, - ITypeSymbol propertyType, - List diagnosticInfos, - CancellationToken token) - { - var result = new PropertyAttributeData(); - - foreach (var attribute in attributes) - { - var displayString = attribute.AttributeClass?.ToDisplayString(); - if (displayString is null) - continue; - - _ = displayString switch - { - Attributes.CellStyle => attribute.TryGetCellStyleAttribute(diagnosticInfos, token, ref result), - Attributes.CellValueTruncate => attribute.TryGetCellValueTruncateAttribute(propertyType, diagnosticInfos, token, ref result), - Attributes.ColumnHeader => attribute.TryGetColumnHeaderAttribute(diagnosticInfos, token, ref result), - Attributes.ColumnOrder => attribute.TryGetColumnOrderAttribute(token, ref result), - Attributes.ColumnWidth => attribute.TryGetColumnWidthAttribute(diagnosticInfos, token, ref result), - Attributes.CellValueConverter => attribute.TryGetCellValueConverterAttribute(propertyType, diagnosticInfos, token, ref result), - _ => false - }; - } - - return result; - } - public static bool TryParseWorksheetRowAttribute( this AttributeData attribute, - CancellationToken token, - [NotNullWhen(true)] out INamedTypeSymbol? typeSymbol, - [NotNullWhen(true)] out Location? location) + [NotNullWhen(true)] out INamedTypeSymbol? typeSymbol) { typeSymbol = null; - location = null; var args = attribute.ConstructorArguments; if (args is not [{ Value: INamedTypeSymbol symbol }]) @@ -55,11 +19,6 @@ public static bool TryParseWorksheetRowAttribute( if (symbol.Kind == SymbolKind.ErrorType) return false; - var syntaxReference = attribute.ApplicationSyntaxReference; - if (syntaxReference is null) - return false; - - location = syntaxReference.GetSyntax(token).GetLocation(); typeSymbol = symbol; return true; } @@ -90,183 +49,4 @@ public static bool TryParseOptionsAttribute( return false; } - - public static InheritedColumnOrder? TryGetInheritedColumnOrderingAttribute(this AttributeData attribute) - { - if (!string.Equals(Attributes.InheritColumns, attribute.AttributeClass?.ToDisplayString(), StringComparison.Ordinal)) - return null; - - if (attribute.NamedArguments is [{ Value.Value: { } arg }] && Enum.IsDefined(typeof(InheritedColumnOrder), arg)) - return (InheritedColumnOrder)arg; - - return InheritedColumnOrder.InheritedColumnsFirst; - } - - private static bool TryGetColumnHeaderAttribute(this AttributeData attribute, - List diagnosticInfos, CancellationToken token, ref PropertyAttributeData result) - { - if (result.ColumnHeader is not null) - return false; - - var args = attribute.ConstructorArguments; - if (args is [{ Value: string } arg]) - result.ColumnHeader = new ColumnHeader(arg.ToCSharpString()); - else if (args is [{ Value: INamedTypeSymbol type }, { Value: string propertyName }]) - result.ColumnHeader = TryGetColumnHeaderWithPropertyReference(type, propertyName, attribute, diagnosticInfos, token); - - return result.ColumnHeader is not null; - } - - private static ColumnHeader? TryGetColumnHeaderWithPropertyReference( - INamedTypeSymbol type, string propertyName, AttributeData attribute, - List diagnosticInfos, CancellationToken token) - { - var typeFullName = type.ToDisplayString(); - - foreach (var member in type.GetMembers()) - { - if (!string.Equals(member.Name, propertyName, StringComparison.Ordinal)) - continue; - - if (!member.IsStaticPropertyWithPublicGetter(out var p)) - break; - - if (p.Type.SpecialType != SpecialType.System_String) - break; - - var propertyReference = new ColumnHeaderPropertyReference(typeFullName, propertyName); - return new ColumnHeader(propertyReference); - } - - var location = attribute.GetLocation(token); - diagnosticInfos.Add(Diagnostics.InvalidColumnHeaderPropertyReference(location, propertyName, typeFullName)); - return null; - } - - private static bool TryGetColumnOrderAttribute(this AttributeData attribute, CancellationToken token, ref PropertyAttributeData result) - { - if (result.ColumnOrder is not null) - return false; - - var args = attribute.ConstructorArguments; - if (args is not [{ Value: int attributeValue }]) - return false; - - var location = attribute.GetLocation(token); - result.ColumnOrder = new ColumnOrder(attributeValue, location); - return true; - } - - private static bool TryGetCellStyleAttribute(this AttributeData attribute, - List diagnosticInfos, CancellationToken token, ref PropertyAttributeData result) - { - if (result.CellStyle is not null) - return false; - - var args = attribute.ConstructorArguments; - if (args is not [{ Value: string value } arg]) - return false; - - if (string.IsNullOrEmpty(value) - || value.Length > 255 - || char.IsWhiteSpace(value[0]) - || char.IsWhiteSpace(value[^1])) - { - diagnosticInfos.Add(Diagnostics.InvalidAttributeArgument(attribute, value, token)); - return false; - } - - result.CellStyle = new CellStyle(arg.ToCSharpString()); - return true; - } - - private static bool TryGetColumnWidthAttribute(this AttributeData attribute, - List diagnosticInfos, CancellationToken token, ref PropertyAttributeData result) - { - if (result.ColumnWidth is not null) - return false; - - var args = attribute.ConstructorArguments; - if (args is not [{ Value: double attributeValue }]) - return false; - - if (attributeValue is <= 0 or > 255) - { - var stringValue = attributeValue.ToString(CultureInfo.InvariantCulture); - diagnosticInfos.Add(Diagnostics.InvalidAttributeArgument(attribute, stringValue, token)); - return false; - } - - result.ColumnWidth = new ColumnWidth(attributeValue); - return true; - } - - private static bool TryGetCellValueTruncateAttribute(this AttributeData attribute, ITypeSymbol propertyType, - List diagnosticInfos, CancellationToken token, ref PropertyAttributeData data) - { - if (data.CellValueTruncate is not null) - return false; - - if (propertyType.SpecialType != SpecialType.System_String) - { - var typeFullName = propertyType.ToDisplayString(); - diagnosticInfos.Add(Diagnostics.UnsupportedTypeForAttribute(attribute, typeFullName, token)); - return false; - } - - var args = attribute.ConstructorArguments; - if (args is not [{ Value: int attributeValue }]) - return false; - - if (attributeValue <= 0) - { - var stringValue = attributeValue.ToString(CultureInfo.InvariantCulture); - diagnosticInfos.Add(Diagnostics.InvalidAttributeArgument(attribute, stringValue, token)); - return false; - } - - data.CellValueTruncate = new CellValueTruncate(attributeValue); - return true; - } - - private static bool TryGetCellValueConverterAttribute(this AttributeData attribute, - ITypeSymbol propertyType, - List diagnosticInfos, CancellationToken token, - ref PropertyAttributeData data) - { - var args = attribute.ConstructorArguments; - if (args is not [{ Value: INamedTypeSymbol converterTypeSymbol }]) - return false; - - var typeName = converterTypeSymbol.ToDisplayString(); - var propertyTypeName = propertyType.OriginalDefinition.ToDisplayString(); - - if (converterTypeSymbol.BaseType is not { Name: "CellValueConverter", TypeArguments: [INamedTypeSymbol typeArgument] } - || !string.Equals(typeArgument.OriginalDefinition.ToDisplayString(), propertyTypeName, StringComparison.Ordinal)) - { - diagnosticInfos.Add(Diagnostics.AttributeTypeArgumentMustInherit(attribute, typeName, $"CellValueConverter<{propertyTypeName}>", token)); - return false; - } - - var hasPublicConstructor = converterTypeSymbol.Constructors.Any(ctor => - ctor is { Parameters.Length: 0, DeclaredAccessibility: Accessibility.Public }); - - if (!hasPublicConstructor) - { - diagnosticInfos.Add(Diagnostics.AttributeTypeArgumentMustHaveDefaultConstructor(attribute, typeName, token)); - return false; - } - - data.CellValueConverter = new CellValueConverter(typeName); - return true; - } - - public static LocationInfo? GetLocation(this AttributeData attribute, CancellationToken token) - { - return attribute - .ApplicationSyntaxReference? - .GetSyntax(token) - .GetLocation() - .ToLocationInfo(); - } } diff --git a/SpreadCheetah.SourceGenerator/Extensions/SymbolExtensions.cs b/SpreadCheetah.SourceGenerator/Extensions/SymbolExtensions.cs index cb398b72..af8a2b50 100644 --- a/SpreadCheetah.SourceGenerator/Extensions/SymbolExtensions.cs +++ b/SpreadCheetah.SourceGenerator/Extensions/SymbolExtensions.cs @@ -1,4 +1,6 @@ using Microsoft.CodeAnalysis; +using SpreadCheetah.SourceGenerator.Helpers; +using SpreadCheetah.SourceGenerator.Models; using System.Diagnostics.CodeAnalysis; namespace SpreadCheetah.SourceGenerator.Extensions; @@ -39,6 +41,18 @@ private static bool IsSupportedNullableType(this ITypeSymbol type) }; } + public static bool IsInstancePropertyWithPublicGetter( + this IPropertySymbol property) + { + return property is + { + DeclaredAccessibility: Accessibility.Public, + IsStatic: false, + IsIndexer: false, + IsWriteOnly: false + }; + } + public static bool IsStaticPropertyWithPublicGetter( this ISymbol symbol, [NotNullWhen(true)] out IPropertySymbol? property) @@ -58,4 +72,63 @@ public static bool IsStaticPropertyWithPublicGetter( property = null; return false; } + + public static IEnumerable GetClassAndBaseClassProperties(this ITypeSymbol type) + { + if ("Object".Equals(type.Name, StringComparison.Ordinal)) + return []; + + InheritedColumnOrder? inheritedColumnOrder = null; + + foreach (var attribute in type.GetAttributes()) + { + if (attribute.TryGetInheritedColumnOrderingAttribute(out var order)) + { + inheritedColumnOrder = order; + break; + } + } + + var properties = type.GetMembers().OfType(); + + if (inheritedColumnOrder is null || type.BaseType is null) + return properties; + + var inheritedProperties = GetClassAndBaseClassProperties(type.BaseType); + + return inheritedColumnOrder switch + { + InheritedColumnOrder.InheritedColumnsFirst => inheritedProperties.Concat(properties), + InheritedColumnOrder.InheritedColumnsLast => properties.Concat(inheritedProperties), + _ => throw new ArgumentOutOfRangeException(nameof(type), "Unsupported inheritance strategy type") + }; + } + + private static bool TryGetInheritedColumnOrderingAttribute(this AttributeData attribute, out InheritedColumnOrder result) + { + result = default; + + if (!string.Equals(Attributes.InheritColumns, attribute.AttributeClass?.ToDisplayString(), StringComparison.Ordinal)) + return false; + + result = attribute.NamedArguments is [{ Value.Value: { } arg }] && Enum.IsDefined(typeof(InheritedColumnOrder), arg) + ? (InheritedColumnOrder)arg + : InheritedColumnOrder.InheritedColumnsFirst; + + return true; + } + + public static AttributeData? GetCellValueConverterAttribute(this IPropertySymbol property) + { + return property + .GetAttributes() + .FirstOrDefault(x => Attributes.CellValueConverter.Equals(x.AttributeClass?.ToDisplayString(), StringComparison.Ordinal)); + } + + public static AttributeData? GetColumnOrderAttribute(this IPropertySymbol property) + { + return property + .GetAttributes() + .FirstOrDefault(x => Attributes.ColumnOrder.Equals(x.AttributeClass?.ToDisplayString(), StringComparison.Ordinal)); + } } diff --git a/SpreadCheetah.SourceGenerator/Helpers/ContextClass.cs b/SpreadCheetah.SourceGenerator/Helpers/ContextClass.cs index 0110059f..ed9dbac6 100644 --- a/SpreadCheetah.SourceGenerator/Helpers/ContextClass.cs +++ b/SpreadCheetah.SourceGenerator/Helpers/ContextClass.cs @@ -7,5 +7,4 @@ internal sealed record ContextClass( string Name, Accessibility DeclaredAccessibility, string? Namespace, - EquatableArray RowTypes, - GeneratorOptions? Options); \ No newline at end of file + EquatableArray RowTypes); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator/Helpers/DiagnosticMap.cs b/SpreadCheetah.SourceGenerator/Helpers/DiagnosticMap.cs deleted file mode 100644 index 25d1abf2..00000000 --- a/SpreadCheetah.SourceGenerator/Helpers/DiagnosticMap.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.CodeAnalysis; -using SpreadCheetah.SourceGenerator.Models; - -namespace SpreadCheetah.SourceGenerator.Helpers; - -internal static class DiagnosticMap -{ - public static Diagnostic ToDiagnostic(this DiagnosticInfo info) - { - return Diagnostic.Create(info.Descriptor, info.Location?.ToLocation(), info.MessageArgs.GetArray()); - } -} diff --git a/SpreadCheetah.SourceGenerator/Helpers/DiagnosticsReporter.cs b/SpreadCheetah.SourceGenerator/Helpers/DiagnosticsReporter.cs new file mode 100644 index 00000000..c1eb55b4 --- /dev/null +++ b/SpreadCheetah.SourceGenerator/Helpers/DiagnosticsReporter.cs @@ -0,0 +1,88 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace SpreadCheetah.SourceGenerator.Helpers; + +internal sealed class DiagnosticsReporter(SymbolAnalysisContext context) : IDiagnosticsReporter +{ + public void ReportAttributeCombinationNotSupported(AttributeData attribute, string otherAttribute, CancellationToken token) + { + var attributeSyntax = attribute.ApplicationSyntaxReference?.GetSyntax(token); + var name = attribute.AttributeClass?.Name; + var diagnostic = Diagnostics.AttributeCombinationNotSupported(attributeSyntax?.GetLocation(), name, otherAttribute); + context.ReportDiagnostic(diagnostic); + } + + public void ReportDuplicateColumnOrdering(AttributeData attribute, CancellationToken token) + { + var attributeSyntax = attribute.ApplicationSyntaxReference?.GetSyntax(token); + var diagnostic = Diagnostics.DuplicateColumnOrder(attributeSyntax?.GetLocation()); + context.ReportDiagnostic(diagnostic); + } + + public void ReportInvalidArgument(AttributeData attribute, CancellationToken token) + { + var location = GetArgument(attribute, token)?.GetLocation(); + var name = attribute.AttributeClass?.Name; + var diagnostic = Diagnostics.InvalidAttributeArgument(location, name); + context.ReportDiagnostic(diagnostic); + } + + public void ReportInvalidPropertyReference(AttributeData attribute, string propertyName, string typeFullName, CancellationToken token) + { + var argList = GetArgumentList(attribute, token); + var diagnostic = Diagnostics.InvalidColumnHeaderPropertyReference(argList?.GetLocation(), propertyName, typeFullName); + context.ReportDiagnostic(diagnostic); + } + + public void ReportNoPropertiesFound(AttributeData attribute, INamedTypeSymbol rowType, CancellationToken token) + { + var location = GetArgument(attribute, token)?.GetLocation(); + var diagnostic = Diagnostics.NoPropertiesFound(location, rowType.Name); + context.ReportDiagnostic(diagnostic); + } + + public void ReportUnsupportedPropertyType(AttributeData attribute, INamedTypeSymbol rowType, IPropertySymbol property, CancellationToken token) + { + var location = GetArgument(attribute, token)?.GetLocation(); + var diagnostic = Diagnostics.UnsupportedTypeForCellValue(location, rowType.Name, property.Name, property.Type.Name); + context.ReportDiagnostic(diagnostic); + } + + public void ReportUnsupportedPropertyTypeForAttribute(AttributeData attribute, ITypeSymbol propertyType, CancellationToken token) + { + var syntaxNode = attribute.ApplicationSyntaxReference?.GetSyntax(token); + var name = attribute.AttributeClass?.Name; + var diagnostic = Diagnostics.UnsupportedTypeForAttribute(syntaxNode?.GetLocation(), name, propertyType.ToDisplayString()); + context.ReportDiagnostic(diagnostic); + } + + public void ReportTypeMustHaveDefaultConstructor(AttributeData attribute, string typeName, CancellationToken token) + { + var location = GetArgument(attribute, token)?.GetLocation(); + var diagnostic = Diagnostics.AttributeTypeArgumentMustHaveDefaultConstructor(location, typeName); + context.ReportDiagnostic(diagnostic); + } + + public void ReportTypeMustInherit(AttributeData attribute, string typeName, string baseClassName, CancellationToken token) + { + var location = GetArgument(attribute, token)?.GetLocation(); + var name = attribute.AttributeClass?.Name; + var diagnostic = Diagnostics.AttributeTypeArgumentMustInherit(location, typeName, name, baseClassName); + context.ReportDiagnostic(diagnostic); + } + + private static AttributeArgumentListSyntax? GetArgumentList(AttributeData attribute, CancellationToken token) + { + var syntaxNode = attribute.ApplicationSyntaxReference?.GetSyntax(token); + var attributeSyntax = syntaxNode as AttributeSyntax; + return attributeSyntax?.ArgumentList; + } + + private static AttributeArgumentSyntax? GetArgument(AttributeData attribute, CancellationToken token) + { + var argList = GetArgumentList(attribute, token); + return argList?.Arguments.FirstOrDefault(); + } +} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator/Helpers/IDiagnosticsReporter.cs b/SpreadCheetah.SourceGenerator/Helpers/IDiagnosticsReporter.cs new file mode 100644 index 00000000..35150111 --- /dev/null +++ b/SpreadCheetah.SourceGenerator/Helpers/IDiagnosticsReporter.cs @@ -0,0 +1,24 @@ +using Microsoft.CodeAnalysis; + +namespace SpreadCheetah.SourceGenerator.Helpers; + +internal interface IDiagnosticsReporter +{ + void ReportAttributeCombinationNotSupported(AttributeData attribute, string otherAttribute, CancellationToken token); + + void ReportDuplicateColumnOrdering(AttributeData attribute, CancellationToken token); + + void ReportInvalidArgument(AttributeData attribute, CancellationToken token); + + void ReportInvalidPropertyReference(AttributeData attribute, string propertyName, string typeFullName, CancellationToken token); + + void ReportNoPropertiesFound(AttributeData attribute, INamedTypeSymbol rowType, CancellationToken token); + + void ReportUnsupportedPropertyType(AttributeData attribute, INamedTypeSymbol rowType, IPropertySymbol property, CancellationToken token); + + void ReportUnsupportedPropertyTypeForAttribute(AttributeData attribute, ITypeSymbol propertyType, CancellationToken token); + + void ReportTypeMustHaveDefaultConstructor(AttributeData attribute, string typeName, CancellationToken token); + + void ReportTypeMustInherit(AttributeData attribute, string typeName, string baseClassName, CancellationToken token); +} diff --git a/SpreadCheetah.SourceGenerator/Helpers/LocationMap.cs b/SpreadCheetah.SourceGenerator/Helpers/LocationMap.cs deleted file mode 100644 index a0aabce8..00000000 --- a/SpreadCheetah.SourceGenerator/Helpers/LocationMap.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.CodeAnalysis; -using SpreadCheetah.SourceGenerator.Models; - -namespace SpreadCheetah.SourceGenerator.Helpers; - -internal static class LocationMap -{ - public static Location ToLocation(this LocationInfo info) - { - return Location.Create(info.FilePath, info.TextSpan, info.LineSpan); - } - - public static LocationInfo? ToLocationInfo(this Location location) - { - if (location.SourceTree is null) - return null; - - return new LocationInfo(location.SourceTree.FilePath, location.SourceSpan, location.GetLineSpan().Span); - } -} diff --git a/SpreadCheetah.SourceGenerator/Helpers/NullDiagnosticsReporter.cs b/SpreadCheetah.SourceGenerator/Helpers/NullDiagnosticsReporter.cs new file mode 100644 index 00000000..1b7adee7 --- /dev/null +++ b/SpreadCheetah.SourceGenerator/Helpers/NullDiagnosticsReporter.cs @@ -0,0 +1,46 @@ +using Microsoft.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; + +namespace SpreadCheetah.SourceGenerator.Helpers; + +[ExcludeFromCodeCoverage] +internal sealed class NullDiagnosticsReporter : IDiagnosticsReporter +{ + public static readonly NullDiagnosticsReporter Instance = new(); + + public void ReportAttributeCombinationNotSupported(AttributeData attribute, string otherAttribute, CancellationToken token) + { + } + + public void ReportDuplicateColumnOrdering(AttributeData attribute, CancellationToken token) + { + } + + public void ReportInvalidArgument(AttributeData attribute, CancellationToken token) + { + } + + public void ReportInvalidPropertyReference(AttributeData attribute, string propertyName, string typeFullName, CancellationToken token) + { + } + + public void ReportNoPropertiesFound(AttributeData attribute, INamedTypeSymbol rowType, CancellationToken token) + { + } + + public void ReportTypeMustHaveDefaultConstructor(AttributeData attribute, string typeName, CancellationToken token) + { + } + + public void ReportTypeMustInherit(AttributeData attribute, string typeName, string baseClassName, CancellationToken token) + { + } + + public void ReportUnsupportedPropertyType(AttributeData attribute, INamedTypeSymbol rowType, IPropertySymbol property, CancellationToken token) + { + } + + public void ReportUnsupportedPropertyTypeForAttribute(AttributeData attribute, ITypeSymbol propertyType, CancellationToken token) + { + } +} diff --git a/SpreadCheetah.SourceGenerator/Helpers/PropertyAnalyzer.cs b/SpreadCheetah.SourceGenerator/Helpers/PropertyAnalyzer.cs new file mode 100644 index 00000000..1bb7541d --- /dev/null +++ b/SpreadCheetah.SourceGenerator/Helpers/PropertyAnalyzer.cs @@ -0,0 +1,178 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using SpreadCheetah.SourceGenerator.Extensions; +using SpreadCheetah.SourceGenerator.Models; + +namespace SpreadCheetah.SourceGenerator.Helpers; + +internal sealed class PropertyAnalyzer(IDiagnosticsReporter diagnostics) +{ + private PropertyAttributeData _result; + + public PropertyAttributeData Analyze(IPropertySymbol property, CancellationToken token) + { + _result = new(); + + foreach (var attribute in property.GetAttributes()) + { + _ = attribute.AttributeClass?.ToDisplayString() switch + { + Attributes.CellStyle => TryGetCellStyleAttribute(attribute, token), + Attributes.CellValueConverter => TryGetCellValueConverterAttribute(attribute, property.Type, token), + Attributes.CellValueTruncate => TryGetCellValueTruncateAttribute(attribute, property.Type, token), + Attributes.ColumnHeader => TryGetColumnHeaderAttribute(attribute, token), + Attributes.ColumnOrder => TryGetColumnOrderAttribute(attribute), + Attributes.ColumnWidth => TryGetColumnWidthAttribute(attribute, token), + _ => false + }; + } + + return _result; + } + + private bool TryGetCellStyleAttribute( + AttributeData attribute, + CancellationToken token) + { + var args = attribute.ConstructorArguments; + if (args is not [{ Value: string value } arg]) + return false; + + if (string.IsNullOrEmpty(value) + || value.Length > 255 + || char.IsWhiteSpace(value[0]) + || char.IsWhiteSpace(value[^1])) + { + diagnostics.ReportInvalidArgument(attribute, token); + return false; + } + + _result.CellStyle = new CellStyle(arg.ToCSharpString()); + return true; + } + + private bool TryGetCellValueConverterAttribute( + AttributeData attribute, + ITypeSymbol propertyType, + CancellationToken token) + { + var args = attribute.ConstructorArguments; + if (args is not [{ Value: INamedTypeSymbol converterTypeSymbol }]) + return false; + + var typeName = converterTypeSymbol.ToDisplayString(); + var propertyTypeName = propertyType.OriginalDefinition.ToDisplayString(); + + if (converterTypeSymbol.BaseType is not { Name: "CellValueConverter", TypeArguments: [INamedTypeSymbol typeArgument] } + || !string.Equals(typeArgument.OriginalDefinition.ToDisplayString(), propertyTypeName, StringComparison.Ordinal)) + { + diagnostics.ReportTypeMustInherit(attribute, typeName, $"CellValueConverter<{propertyTypeName}>", token); + return false; + } + + var hasPublicConstructor = converterTypeSymbol.Constructors.Any(ctor => + ctor is { Parameters.Length: 0, DeclaredAccessibility: Accessibility.Public }); + + if (!hasPublicConstructor) + { + diagnostics.ReportTypeMustHaveDefaultConstructor(attribute, typeName, token); + return false; + } + + _result.CellValueConverter = new CellValueConverter(typeName); + return true; + } + + private bool TryGetCellValueTruncateAttribute( + AttributeData attribute, + ITypeSymbol propertyType, + CancellationToken token) + { + if (propertyType.SpecialType != SpecialType.System_String) + { + diagnostics.ReportUnsupportedPropertyTypeForAttribute(attribute, propertyType, token); + return false; + } + + var args = attribute.ConstructorArguments; + if (args is not [{ Value: int attributeValue }]) + return false; + + if (attributeValue <= 0) + { + diagnostics.ReportInvalidArgument(attribute, token); + return false; + } + + _result.CellValueTruncate = new CellValueTruncate(attributeValue); + return true; + } + + private bool TryGetColumnHeaderAttribute( + AttributeData attribute, + CancellationToken token) + { + var args = attribute.ConstructorArguments; + if (args is [{ Value: string } arg]) + _result.ColumnHeader = new ColumnHeader(arg.ToCSharpString()); + else if (args is [{ Value: INamedTypeSymbol type }, { Value: string propertyName }]) + _result.ColumnHeader = TryGetColumnHeaderWithPropertyReference(type, propertyName, attribute, token); + + return _result.ColumnHeader is not null; + } + + private ColumnHeader? TryGetColumnHeaderWithPropertyReference( + INamedTypeSymbol type, + string propertyName, + AttributeData attribute, + CancellationToken token) + { + var typeFullName = type.ToDisplayString(); + + foreach (var member in type.GetMembers()) + { + if (!string.Equals(member.Name, propertyName, StringComparison.Ordinal)) + continue; + + if (!member.IsStaticPropertyWithPublicGetter(out var p)) + break; + + if (p.Type.SpecialType != SpecialType.System_String) + break; + + var propertyReference = new ColumnHeaderPropertyReference(typeFullName, propertyName); + return new ColumnHeader(propertyReference); + } + + diagnostics.ReportInvalidPropertyReference(attribute, propertyName, typeFullName, token); + return null; + } + + private bool TryGetColumnOrderAttribute(AttributeData attribute) + { + var args = attribute.ConstructorArguments; + if (args is not [{ Value: int attributeValue }]) + return false; + + _result.ColumnOrder = new ColumnOrder(attributeValue); + return true; + } + + private bool TryGetColumnWidthAttribute( + AttributeData attribute, + CancellationToken token) + { + var args = attribute.ConstructorArguments; + if (args is not [{ Value: double attributeValue }]) + return false; + + if (attributeValue is <= 0 or > 255) + { + diagnostics.ReportInvalidArgument(attribute, token); + return false; + } + + _result.ColumnWidth = new ColumnWidth(attributeValue); + return true; + } +} diff --git a/SpreadCheetah.SourceGenerator/Models/ColumnOrder.cs b/SpreadCheetah.SourceGenerator/Models/ColumnOrder.cs index 7af07976..deb81fae 100644 --- a/SpreadCheetah.SourceGenerator/Models/ColumnOrder.cs +++ b/SpreadCheetah.SourceGenerator/Models/ColumnOrder.cs @@ -1,3 +1,3 @@ namespace SpreadCheetah.SourceGenerator.Models; -internal readonly record struct ColumnOrder(int Value, LocationInfo? Location); \ No newline at end of file +internal readonly record struct ColumnOrder(int Value); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator/Models/DiagnosticInfo.cs b/SpreadCheetah.SourceGenerator/Models/DiagnosticInfo.cs deleted file mode 100644 index 624f514d..00000000 --- a/SpreadCheetah.SourceGenerator/Models/DiagnosticInfo.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Microsoft.CodeAnalysis; -using SpreadCheetah.SourceGenerator.Helpers; - -namespace SpreadCheetah.SourceGenerator.Models; - -internal sealed record DiagnosticInfo( - DiagnosticDescriptor Descriptor, - LocationInfo? Location, - EquatableArray MessageArgs); diff --git a/SpreadCheetah.SourceGenerator/Models/LocationInfo.cs b/SpreadCheetah.SourceGenerator/Models/LocationInfo.cs deleted file mode 100644 index d7e8b467..00000000 --- a/SpreadCheetah.SourceGenerator/Models/LocationInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Microsoft.CodeAnalysis.Text; - -namespace SpreadCheetah.SourceGenerator.Models; - -internal sealed record LocationInfo( - string FilePath, - TextSpan TextSpan, - LinePositionSpan LineSpan); \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator/Models/RowType.cs b/SpreadCheetah.SourceGenerator/Models/RowType.cs index 38b0ee03..82cfb558 100644 --- a/SpreadCheetah.SourceGenerator/Models/RowType.cs +++ b/SpreadCheetah.SourceGenerator/Models/RowType.cs @@ -7,10 +7,7 @@ internal sealed record RowType( string FullName, bool IsReferenceType, int PropertiesWithStyleAttributes, - LocationInfo? WorksheetRowAttributeLocation, - EquatableArray Properties, - EquatableArray UnsupportedPropertyTypeNames, - EquatableArray DiagnosticInfos) + EquatableArray Properties) { public string CellType { get; } = PropertiesWithStyleAttributes > 0 ? "StyledCell" : "DataCell"; public string FullNameWithNullableAnnotation => IsReferenceType ? $"{FullName}?" : FullName; diff --git a/SpreadCheetah.SourceGenerator/WorksheetRowAnalyzer.cs b/SpreadCheetah.SourceGenerator/WorksheetRowAnalyzer.cs new file mode 100644 index 00000000..bbf30fb2 --- /dev/null +++ b/SpreadCheetah.SourceGenerator/WorksheetRowAnalyzer.cs @@ -0,0 +1,141 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; +using SpreadCheetah.SourceGenerator; +using SpreadCheetah.SourceGenerator.Extensions; +using SpreadCheetah.SourceGenerator.Helpers; +using System.Collections.Immutable; + +namespace SpreadCheetah.SourceGenerators; + +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class WorksheetRowAnalyzer : DiagnosticAnalyzer +{ + public override ImmutableArray SupportedDiagnostics => Diagnostics.AllDescriptors; + + public override void Initialize(AnalysisContext context) + { + if (context is null) + throw new ArgumentNullException(nameof(context)); + + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); + context.EnableConcurrentExecution(); + + context.RegisterSymbolAction(AnalyzeContextType, SymbolKind.NamedType); + context.RegisterSymbolAction(AnalyzeRowType, SymbolKind.NamedType); + context.RegisterSymbolAction(AnalyzeRowTypeProperty, SymbolKind.Property); + } + + private static void AnalyzeContextType(SymbolAnalysisContext context) + { + if (context.Symbol is not INamedTypeSymbol type) + return; + if (type is not { IsStatic: false, BaseType: { } baseType }) + return; + if (!"SpreadCheetah.SourceGeneration.WorksheetRowContext".Equals(baseType.ToDisplayString(), StringComparison.Ordinal)) + return; + if (type.GetAttributes() is { Length: 0 } attributes) + return; + + var suppressWarnings = false; + + foreach (var attribute in attributes) + { + if (attribute.TryParseOptionsAttribute(out var options)) + { + suppressWarnings = options.SuppressWarnings; + break; + } + } + + // Right now the diagnostics below are just warnings. + // If that changes, then this part here must also change. + if (suppressWarnings) + return; + + var diagnostics = new DiagnosticsReporter(context); + + foreach (var attribute in attributes) + { + if (!attribute.TryParseWorksheetRowAttribute(out var rowType)) + continue; + + var properties = rowType + .GetClassAndBaseClassProperties() + .Where(x => x.IsInstancePropertyWithPublicGetter()); + + var hasProperties = false; + + foreach (var property in properties) + { + hasProperties = true; + + var cellValueConverter = property.GetCellValueConverterAttribute(); + if (cellValueConverter is not null) + continue; + if (property.Type.IsSupportedType()) + continue; + + diagnostics.ReportUnsupportedPropertyType(attribute, rowType, property, context.CancellationToken); + break; + } + + if (!hasProperties) + diagnostics.ReportNoPropertiesFound(attribute, rowType, context.CancellationToken); + } + } + + private static void AnalyzeRowType(SymbolAnalysisContext context) + { + if (context.Symbol is not INamedTypeSymbol type) + return; + + var typeHasColumnOrderAttribute = type + .GetMembers() + .OfType() + .Any(x => x.GetColumnOrderAttribute() is not null); + + // Avoid duplicate column order on base class from emitting the same error for each derived class. + // Also some extra work is avoided for types that don't use the attribute. + if (!typeHasColumnOrderAttribute) + return; + + var diagnostics = new DiagnosticsReporter(context); + var columnOrderValues = new HashSet(); + + foreach (var property in type.GetClassAndBaseClassProperties()) + { + var columnOrderAttribute = property.GetColumnOrderAttribute(); + if (columnOrderAttribute is null) + continue; + + var args = columnOrderAttribute.ConstructorArguments; + if (args is not [{ Value: int attributeValue }]) + continue; + + if (!columnOrderValues.Add(attributeValue)) + diagnostics.ReportDuplicateColumnOrdering(columnOrderAttribute, context.CancellationToken); + } + } + + private static void AnalyzeRowTypeProperty(SymbolAnalysisContext context) + { + if (context.Symbol is not IPropertySymbol property) + return; + if (property.GetAttributes() is { Length: 0 } attributes) + return; + + var diagnostics = new DiagnosticsReporter(context); + var analyzer = new PropertyAnalyzer(diagnostics); + + var data = analyzer.Analyze(property, context.CancellationToken); + + if (data is { CellValueConverter: not null, CellValueTruncate: not null }) + { + var cellValueTruncateAttribute = attributes + .First(x => Attributes.CellValueTruncate.Equals(x.AttributeClass?.ToDisplayString(), StringComparison.Ordinal)); + + diagnostics.ReportAttributeCombinationNotSupported(cellValueTruncateAttribute, + "CellValueConverterAttribute", context.CancellationToken); + } + } +} \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator/WorksheetRowGenerator.cs b/SpreadCheetah.SourceGenerator/WorksheetRowGenerator.cs index b1d619d8..aafee0d4 100644 --- a/SpreadCheetah.SourceGenerator/WorksheetRowGenerator.cs +++ b/SpreadCheetah.SourceGenerator/WorksheetRowGenerator.cs @@ -50,10 +50,10 @@ private static bool IsSyntaxTargetForGeneration(SyntaxNode syntaxNode, Cancellat foreach (var attribute in context.Attributes) { - if (!attribute.TryParseWorksheetRowAttribute(token, out var typeSymbol, out var location)) + if (!attribute.TryParseWorksheetRowAttribute(out var typeSymbol)) continue; - var rowType = AnalyzeTypeProperties(typeSymbol, location.ToLocationInfo(), token); + var rowType = AnalyzeTypeProperties(typeSymbol, token); if (!rowTypes.Exists(x => string.Equals(x.FullName, rowType.FullName, StringComparison.Ordinal))) rowTypes.Add(rowType); } @@ -61,47 +61,30 @@ private static bool IsSyntaxTargetForGeneration(SyntaxNode syntaxNode, Cancellat if (rowTypes.Count == 0) return null; - GeneratorOptions? generatorOptions = null; - - foreach (var attribute in classSymbol.GetAttributes()) - { - if (attribute.TryParseOptionsAttribute(out var options)) - { - generatorOptions = options; - break; - } - } - return new ContextClass( DeclaredAccessibility: classSymbol.DeclaredAccessibility, Namespace: classSymbol.ContainingNamespace is { IsGlobalNamespace: false } ns ? ns.ToString() : null, Name: classSymbol.Name, - RowTypes: rowTypes.ToEquatableArray(), - Options: generatorOptions); + RowTypes: rowTypes.ToEquatableArray()); } - private static RowType AnalyzeTypeProperties(ITypeSymbol classType, LocationInfo? worksheetRowAttributeLocation, CancellationToken token) + private static RowType AnalyzeTypeProperties(ITypeSymbol rowType, CancellationToken token) { var implicitOrderProperties = new List(); var explicitOrderProperties = new SortedDictionary(); - var unsupportedPropertyTypeNames = new HashSet(StringComparer.Ordinal); - var diagnosticInfos = new List(); var propertiesWithStyleAttributes = 0; + var analyzer = new PropertyAnalyzer(NullDiagnosticsReporter.Instance); - foreach (var property in GetClassAndBaseClassProperties(classType)) - { - if (property.IsWriteOnly || property.IsStatic || property.DeclaredAccessibility != Accessibility.Public) - continue; + var properties = rowType + .GetClassAndBaseClassProperties() + .Where(x => x.IsInstancePropertyWithPublicGetter()); - var data = property - .GetAttributes() - .MapToPropertyAttributeData(property.Type, diagnosticInfos, token); + foreach (var property in properties) + { + var data = analyzer.Analyze(property, token); if (data.CellValueConverter is null && !property.Type.IsSupportedType()) - { - unsupportedPropertyTypeNames.Add(property.Type.Name); continue; - } if (data.CellStyle is not null) propertiesWithStyleAttributes++; @@ -114,60 +97,20 @@ private static RowType AnalyzeTypeProperties(ITypeSymbol classType, LocationInfo CellValueTruncate: data.CellValueTruncate, CellValueConverter: data.CellValueConverter); - if (data is { CellValueConverter: not null, CellValueTruncate: not null }) - { - var location = property.Locations.FirstOrDefault()?.ToLocationInfo(); - diagnosticInfos.Add(Diagnostics.AttributeCombinationNotSupported(location, "CellValueConverter", "CellValueTruncate")); - } - if (data.ColumnOrder is not { } order) implicitOrderProperties.Add(rowTypeProperty); else if (!explicitOrderProperties.ContainsKey(order.Value)) explicitOrderProperties.Add(order.Value, rowTypeProperty); - else - diagnosticInfos.Add(Diagnostics.DuplicateColumnOrder(order.Location, classType.Name)); } explicitOrderProperties.AddWithImplicitKeys(implicitOrderProperties); return new RowType( - DiagnosticInfos: diagnosticInfos.ToEquatableArray(), - FullName: classType.ToString(), - IsReferenceType: classType.IsReferenceType, - Name: classType.Name, + FullName: rowType.ToString(), + IsReferenceType: rowType.IsReferenceType, + Name: rowType.Name, Properties: explicitOrderProperties.Values.ToEquatableArray(), - PropertiesWithStyleAttributes: propertiesWithStyleAttributes, - UnsupportedPropertyTypeNames: unsupportedPropertyTypeNames.ToEquatableArray(), - WorksheetRowAttributeLocation: worksheetRowAttributeLocation); - } - - private static IEnumerable GetClassAndBaseClassProperties(ITypeSymbol? classType) - { - if (classType is null || string.Equals(classType.Name, "Object", StringComparison.Ordinal)) - { - return []; - } - - var inheritedColumnOrderStrategy = classType.GetAttributes() - .Where(data => data.TryGetInheritedColumnOrderingAttribute().HasValue) - .Select(data => data.TryGetInheritedColumnOrderingAttribute()) - .FirstOrDefault(); - - var classProperties = classType.GetMembers().OfType(); - - if (inheritedColumnOrderStrategy is null) - { - return classProperties; - } - - var inheritedProperties = GetClassAndBaseClassProperties(classType.BaseType); - - return inheritedColumnOrderStrategy switch - { - InheritedColumnOrder.InheritedColumnsFirst => inheritedProperties.Concat(classProperties), - InheritedColumnOrder.InheritedColumnsLast => classProperties.Concat(inheritedProperties), - _ => throw new ArgumentOutOfRangeException(nameof(classType), "Unsupported inheritance strategy type") - }; + PropertiesWithStyleAttributes: propertiesWithStyleAttributes); } private static void Execute(ContextClass? contextClass, SourceProductionContext context) @@ -176,7 +119,7 @@ private static void Execute(ContextClass? contextClass, SourceProductionContext return; var sb = new StringBuilder(); - GenerateCode(sb, contextClass, context); + GenerateCode(sb, contextClass); var hintName = contextClass.Namespace is { } ns ? $"{ns}.{contextClass.Name}.g.cs" @@ -202,7 +145,7 @@ private static void GenerateHeader(StringBuilder sb) """); } - private static void GenerateCode(StringBuilder sb, ContextClass contextClass, SourceProductionContext context) + private static void GenerateCode(StringBuilder sb, ContextClass contextClass) { GenerateHeader(sb); @@ -234,7 +177,7 @@ private static void GenerateCode(StringBuilder sb, ContextClass contextClass, So if (!rowTypeNames.Add(rowTypeName)) continue; - GenerateCodeForType(sb, typeIndex, cellValueConverters, rowType, contextClass, context); + GenerateCodeForType(sb, typeIndex, cellValueConverters, rowType); ++typeIndex; } @@ -247,11 +190,8 @@ private static void GenerateCode(StringBuilder sb, ContextClass contextClass, So } private static void GenerateCodeForType(StringBuilder sb, int typeIndex, - Dictionary cellValueConverters, RowType rowType, - ContextClass contextClass, SourceProductionContext context) + Dictionary cellValueConverters, RowType rowType) { - ReportDiagnostics(rowType, rowType.WorksheetRowAttributeLocation, contextClass.Options, context); - sb.AppendLine().AppendLine($$""" private WorksheetRowTypeInfo<{{rowType.FullName}}>? _{{rowType.Name}}; public WorksheetRowTypeInfo<{{rowType.FullName}}> {{rowType.Name}} => _{{rowType.Name}} @@ -300,30 +240,6 @@ private static void GenerateCodeForType(StringBuilder sb, int typeIndex, GenerateAddCellsAsRow(sb, rowType, cellStyleToStyleIdIndex, cellValueConverters); } - private static void ReportDiagnostics(RowType rowType, LocationInfo? locationInfo, GeneratorOptions? options, SourceProductionContext context) - { - var suppressWarnings = options?.SuppressWarnings ?? false; - - foreach (var diagnosticInfo in rowType.DiagnosticInfos) - { - var isWarning = diagnosticInfo.Descriptor.DefaultSeverity == DiagnosticSeverity.Warning; - if (isWarning && suppressWarnings) - continue; - - context.ReportDiagnostic(diagnosticInfo.ToDiagnostic()); - } - - if (suppressWarnings) return; - - var location = locationInfo?.ToLocation(); - - if (rowType.Properties.Count == 0) - context.ReportDiagnostic(Diagnostics.NoPropertiesFound(location, rowType.Name)); - - if (rowType.UnsupportedPropertyTypeNames.FirstOrDefault() is { } unsupportedPropertyTypeName) - context.ReportDiagnostic(Diagnostics.UnsupportedTypeForCellValue(location, rowType.Name, unsupportedPropertyTypeName)); - } - private static void GenerateCreateWorksheetOptions(StringBuilder sb, int typeIndex, EquatableArray properties) { Debug.Assert(properties.Any(static x => x.ColumnWidth is not null)); diff --git a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet6_0.verified.txt b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet6_0.verified.txt index 98d4581c..52b22d64 100644 --- a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet6_0.verified.txt +++ b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet6_0.verified.txt @@ -254,6 +254,8 @@ namespace SpreadCheetah.SourceGeneration public sealed class WorksheetRowGenerationOptionsAttribute : System.Attribute { public WorksheetRowGenerationOptionsAttribute() { } + [System.Obsolete("Configure rule severity in an .editorconfig file instead (e.g. \'dotnet_diagnostic" + + ".SPCH1001.severity = none\').")] public bool SuppressWarnings { get; set; } } public static class WorksheetRowMetadataServices diff --git a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet7_0.verified.txt b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet7_0.verified.txt index a5a4c7bf..318fdfb6 100644 --- a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet7_0.verified.txt +++ b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet7_0.verified.txt @@ -254,6 +254,8 @@ namespace SpreadCheetah.SourceGeneration public sealed class WorksheetRowGenerationOptionsAttribute : System.Attribute { public WorksheetRowGenerationOptionsAttribute() { } + [System.Obsolete("Configure rule severity in an .editorconfig file instead (e.g. \'dotnet_diagnostic" + + ".SPCH1001.severity = none\').")] public bool SuppressWarnings { get; set; } } public static class WorksheetRowMetadataServices diff --git a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet8_0.verified.txt b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet8_0.verified.txt index ff83060a..3ea7923c 100644 --- a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet8_0.verified.txt +++ b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.DotNet8_0.verified.txt @@ -254,6 +254,8 @@ namespace SpreadCheetah.SourceGeneration public sealed class WorksheetRowGenerationOptionsAttribute : System.Attribute { public WorksheetRowGenerationOptionsAttribute() { } + [System.Obsolete("Configure rule severity in an .editorconfig file instead (e.g. \'dotnet_diagnostic" + + ".SPCH1001.severity = none\').")] public bool SuppressWarnings { get; set; } } public static class WorksheetRowMetadataServices diff --git a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.Net4_7.verified.txt b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.Net4_7.verified.txt index 890e6fec..ef3b0858 100644 --- a/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.Net4_7.verified.txt +++ b/SpreadCheetah.Test/Tests/PublicApiTests.PublicApi_Generate.Net4_7.verified.txt @@ -253,6 +253,8 @@ namespace SpreadCheetah.SourceGeneration public sealed class WorksheetRowGenerationOptionsAttribute : System.Attribute { public WorksheetRowGenerationOptionsAttribute() { } + [System.Obsolete("Configure rule severity in an .editorconfig file instead (e.g. \'dotnet_diagnostic" + + ".SPCH1001.severity = none\').")] public bool SuppressWarnings { get; set; } } public static class WorksheetRowMetadataServices diff --git a/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs b/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs index cb7d4e2b..f1c15f4d 100644 --- a/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs +++ b/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs @@ -5,7 +5,6 @@ using SpreadCheetah.Images; using SpreadCheetah.Test.Helpers; using System.IO.Compression; -using Xunit; namespace SpreadCheetah.Test.Tests; @@ -286,10 +285,10 @@ public async Task Spreadsheet_AddImage_PngInSecondWorksheet() SpreadsheetAssert.Valid(outputStream); using var workbook = new XLWorkbook(outputStream); - var worksheet1 = Assert.Single(workbook.Worksheets.Where(x => !string.Equals(worksheetName, x.Name, StringComparison.Ordinal))); + var worksheet1 = Assert.Single(workbook.Worksheets, x => !string.Equals(worksheetName, x.Name, StringComparison.Ordinal)); Assert.Empty(worksheet1.Pictures); - var worksheet2 = Assert.Single(workbook.Worksheets.Where(x => string.Equals(worksheetName, x.Name, StringComparison.Ordinal))); + var worksheet2 = Assert.Single(workbook.Worksheets, x => string.Equals(worksheetName, x.Name, StringComparison.Ordinal)); var picture = Assert.Single(worksheet2.Pictures); Assert.Equal(reference, picture.TopLeftCell.Address.ToString()); Assert.Equal(XLPictureFormat.Png, picture.Format); diff --git a/SpreadCheetah.TestHelpers/Extensions/EnumerableExtensions.cs b/SpreadCheetah.TestHelpers/Extensions/EnumerableExtensions.cs new file mode 100644 index 00000000..b62b50c6 --- /dev/null +++ b/SpreadCheetah.TestHelpers/Extensions/EnumerableExtensions.cs @@ -0,0 +1,11 @@ +using SpreadCheetah.TestHelpers.Assertions; + +namespace SpreadCheetah.TestHelpers.Extensions; + +public static class EnumerableExtensions +{ + public static IEnumerable StringValues(this IEnumerable cells) + { + return cells.Select(x => x.StringValue); + } +} diff --git a/SpreadCheetah/SourceGeneration/WorksheetRowGenerationOptionsAttribute.cs b/SpreadCheetah/SourceGeneration/WorksheetRowGenerationOptionsAttribute.cs index e9c0551a..b55b7d51 100644 --- a/SpreadCheetah/SourceGeneration/WorksheetRowGenerationOptionsAttribute.cs +++ b/SpreadCheetah/SourceGeneration/WorksheetRowGenerationOptionsAttribute.cs @@ -9,5 +9,6 @@ public sealed class WorksheetRowGenerationOptionsAttribute : Attribute /// /// Specifies whether to suppress warnings from the source generator. /// + [Obsolete("Configure rule severity in an .editorconfig file instead (e.g. 'dotnet_diagnostic.SPCH1001.severity = none').")] public bool SuppressWarnings { get; set; } }