diff --git a/.editorconfig b/.editorconfig index 77dfa19a..86b3f62d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -153,6 +153,8 @@ dotnet_diagnostic.IDE0028.severity = warning dotnet_diagnostic.IDE0300.severity = warning # IDE0301: Use collection expression for empty dotnet_diagnostic.IDE0301.severity = warning +# IDE0305: Use collection expression for fluent +dotnet_diagnostic.IDE0305.severity = warning [{ColumnHeaderAttribute.cs,ColumnOrderAttribute.cs,WorksheetRowAttribute.cs}] # CA1019: Define accessors for attribute arguments diff --git a/SpreadCheetah.SourceGenerator/Extensions/EnumerableExtensions.cs b/SpreadCheetah.SourceGenerator/Extensions/EnumerableExtensions.cs index e9bfe177..dbaceb0d 100644 --- a/SpreadCheetah.SourceGenerator/Extensions/EnumerableExtensions.cs +++ b/SpreadCheetah.SourceGenerator/Extensions/EnumerableExtensions.cs @@ -12,7 +12,7 @@ internal static class EnumerableExtensions public static EquatableArray ToEquatableArray(this IEnumerable elements) where T : IEquatable { - var array = elements is T[] arr ? arr : elements.ToArray(); + var array = elements is T[] arr ? arr : [.. elements]; return new EquatableArray(array); } } diff --git a/SpreadCheetah/MetadataXml/StylesXml.cs b/SpreadCheetah/MetadataXml/StylesXml.cs index 58cd378e..e96d3e84 100644 --- a/SpreadCheetah/MetadataXml/StylesXml.cs +++ b/SpreadCheetah/MetadataXml/StylesXml.cs @@ -15,7 +15,7 @@ public static ValueTask WriteAsync( CancellationToken token) { var entry = archive.CreateEntry("xl/styles.xml", compressionLevel); - var writer = new StylesXml(styles.Keys.ToList()); + var writer = new StylesXml([.. styles.Keys]); #pragma warning disable EPS06 // Hidden struct copy operation return writer.WriteAsync(entry, buffer, token); #pragma warning restore EPS06 // Hidden struct copy operation @@ -51,10 +51,10 @@ private StylesXml(List styles) _borders = CreateBorderDictionary(styles); _fills = CreateFillDictionary(styles); _fonts = CreateFontDictionary(styles); - _numberFormatsXml = new StyleNumberFormatsXml(_customNumberFormats?.ToList()); - _bordersXml = new StyleBordersXml(_borders.Keys.ToList()); - _fillsXml = new StyleFillsXml(_fills.Keys.ToList()); - _fontsXml = new StyleFontsXml(_fonts.Keys.ToList()); + _numberFormatsXml = new StyleNumberFormatsXml(_customNumberFormats is { } formats ? [.. formats] : null); + _bordersXml = new StyleBordersXml([.. _borders.Keys]); + _fillsXml = new StyleFillsXml([.. _fills.Keys]); + _fontsXml = new StyleFontsXml([.. _fonts.Keys]); _styles = styles; } diff --git a/SpreadCheetah/MetadataXml/WorksheetStartXml.cs b/SpreadCheetah/MetadataXml/WorksheetStartXml.cs index f12b3e7b..e120cbf2 100644 --- a/SpreadCheetah/MetadataXml/WorksheetStartXml.cs +++ b/SpreadCheetah/MetadataXml/WorksheetStartXml.cs @@ -21,7 +21,7 @@ internal struct WorksheetStartXml : IXmlWriter public WorksheetStartXml(WorksheetOptions? options) { _options = options; - _columns = options?.ColumnOptions.ToList(); + _columns = options is not null ? [.. options.ColumnOptions] : null; } public bool TryWrite(Span bytes, out int bytesWritten)