From 55c816c1ead3771840630e2db00c302499ec7d7e Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Fri, 29 Jul 2022 19:11:45 -0600 Subject: [PATCH 1/3] Avoid allocating empty arrays CA1825: Avoid zero-length array allocations https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1825 --- .../Images/AddImageMetadataTests.cs | 4 ++-- src/TaglibSharp.Tests/Images/CopyFromTest.cs | 8 ++++---- .../Images/GifExiftoolLongCommentTest.cs | 4 +++- .../Images/GifExiftoolTangled3Test.cs | 4 +++- src/TaglibSharp.Tests/Images/ImageTagTests.cs | 4 +++- .../Images/JpegNikon1Bibble5Test.cs | 4 +++- .../Images/JpegNikon2Bibble5Test.cs | 4 +++- .../Images/JpegOlympus2Test.cs | 2 +- .../Images/PefPentaxKd10Test.cs | 2 +- .../Images/RawLeicaDigilux2Test.cs | 2 +- .../Images/RecursiveIFDTest.cs | 4 +++- .../Images/Rw2PanasonicG1Test.cs | 2 +- .../Images/TiffCanonBibble516BitTest.cs | 4 +++- .../Images/TiffCanonBibble58BitTest.cs | 4 +++- .../Images/TiffNikon1Bibble516BitTest.cs | 4 +++- .../Images/TiffNikon1Bibble58BitTest.cs | 4 +++- .../Images/TiffNikon2Bibble516BitTest.cs | 4 +++- .../Images/TiffNikon2Bibble58BitTest.cs | 4 +++- .../KeywordsModificationValidator.cs | 4 +++- .../TagKeywordsModificationValidator.cs | 4 +++- .../TaggingFormats/ApeTest.cs | 12 +++++++----- .../TaggingFormats/AsfTest.cs | 12 +++++++----- .../TaggingFormats/DivXTest.cs | 6 ++++-- .../TaggingFormats/Id3V1Test.cs | 6 ++++-- .../TaggingFormats/Id3V2Test.cs | 12 +++++++----- .../TaggingFormats/InfoTagTest.cs | 10 ++++++---- .../TaggingFormats/MovieIdTagTest.cs | 6 ++++-- .../TaggingFormats/Mpeg4Test.cs | 12 +++++++----- .../TaggingFormats/XiphTest.cs | 10 +++++----- src/TaglibSharp/Ape/Item.cs | 2 +- src/TaglibSharp/Ape/Tag.cs | 2 +- src/TaglibSharp/Asf/Tag.cs | 4 ++-- src/TaglibSharp/CombinedTag.cs | 16 ++++++++-------- src/TaglibSharp/Id3v1/Tag.cs | 4 ++-- .../Id3v2/Frames/SynchronizedLyricsFrame.cs | 5 +++-- .../Id3v2/Frames/TextIdentificationFrame.cs | 6 +++--- src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs | 6 +++--- src/TaglibSharp/Id3v2/Tag.cs | 6 +++--- src/TaglibSharp/Image/CombinedImageTag.cs | 2 +- src/TaglibSharp/Image/ImageTag.cs | 2 +- src/TaglibSharp/Matroska/Tag.cs | 2 +- src/TaglibSharp/Matroska/Tags.cs | 4 ++-- src/TaglibSharp/Ogg/GroupedComment.cs | 18 +++++++++--------- src/TaglibSharp/Ogg/Paginator.cs | 2 +- src/TaglibSharp/Ogg/XiphComment.cs | 6 +++--- src/TaglibSharp/Properties.cs | 2 +- src/TaglibSharp/Riff/DivXTag.cs | 4 ++-- src/TaglibSharp/Riff/File.cs | 2 +- src/TaglibSharp/Tag.cs | 18 +++++++++--------- src/TaglibSharp/Xmp/XmpTag.cs | 2 +- 50 files changed, 161 insertions(+), 116 deletions(-) diff --git a/src/TaglibSharp.Tests/Images/AddImageMetadataTests.cs b/src/TaglibSharp.Tests/Images/AddImageMetadataTests.cs index d6f1c10e3..a73cfbccf 100644 --- a/src/TaglibSharp.Tests/Images/AddImageMetadataTests.cs +++ b/src/TaglibSharp.Tests/Images/AddImageMetadataTests.cs @@ -108,7 +108,7 @@ public static void AddXMPTest2 (string sample_file, string tmp_file, bool contai xmp_tag.Comment = null; xmp_tag.Software = test_comment; - Assert.AreEqual (new string[] { }, xmp_tag.Keywords); + Assert.AreEqual (Array.Empty (), xmp_tag.Keywords); Assert.AreEqual (null, xmp_tag.Comment); Assert.AreEqual (test_comment, xmp_tag.Software); @@ -119,7 +119,7 @@ public static void AddXMPTest2 (string sample_file, string tmp_file, bool contai xmp_tag = file.GetTag (TagTypes.XMP, false) as XmpTag; Assert.IsNotNull (xmp_tag, "XMP Tag not read"); - Assert.AreEqual (new string[] { }, xmp_tag.Keywords); + Assert.AreEqual (Array.Empty (), xmp_tag.Keywords); Assert.AreEqual (null, xmp_tag.Comment); Assert.AreEqual (test_comment, xmp_tag.Software); } diff --git a/src/TaglibSharp.Tests/Images/CopyFromTest.cs b/src/TaglibSharp.Tests/Images/CopyFromTest.cs index d30b6fc80..01c180089 100644 --- a/src/TaglibSharp.Tests/Images/CopyFromTest.cs +++ b/src/TaglibSharp.Tests/Images/CopyFromTest.cs @@ -21,8 +21,8 @@ public void TestJPGtoTIFF () Assert.AreEqual (TagTypes.TiffIFD | TagTypes.XMP, file2.TagTypes); Assert.AreEqual ("%test comment%", file1.ImageTag.Comment); Assert.AreEqual (string.Empty, file2.ImageTag.Comment); - Assert.AreEqual (new string[] { }, file1.ImageTag.Keywords); - Assert.AreEqual (new string[] { }, file2.ImageTag.Keywords); + Assert.AreEqual (Array.Empty (), file1.ImageTag.Keywords); + Assert.AreEqual (Array.Empty (), file2.ImageTag.Keywords); Assert.AreEqual (null, file1.ImageTag.Rating); Assert.AreEqual (0, file2.ImageTag.Rating); Assert.AreEqual (new DateTime (2009, 8, 9, 19, 12, 44), (DateTime)file1.ImageTag.DateTime); @@ -62,8 +62,8 @@ public void TestJPGtoTIFF () Assert.AreEqual (TagTypes.TiffIFD | TagTypes.XMP, file2.TagTypes); Assert.AreEqual ("%test comment%", file1.ImageTag.Comment); Assert.AreEqual ("%test comment%", file2.ImageTag.Comment); - Assert.AreEqual (new string[] { }, file1.ImageTag.Keywords); - Assert.AreEqual (new string[] { }, file2.ImageTag.Keywords); + Assert.AreEqual (Array.Empty (), file1.ImageTag.Keywords); + Assert.AreEqual (Array.Empty (), file2.ImageTag.Keywords); Assert.AreEqual (null, file1.ImageTag.Rating); Assert.AreEqual (null, file2.ImageTag.Rating); Assert.AreEqual (new DateTime (2009, 8, 9, 19, 12, 44), (DateTime)file1.ImageTag.DateTime); diff --git a/src/TaglibSharp.Tests/Images/GifExiftoolLongCommentTest.cs b/src/TaglibSharp.Tests/Images/GifExiftoolLongCommentTest.cs index 03706347e..55dc61063 100644 --- a/src/TaglibSharp.Tests/Images/GifExiftoolLongCommentTest.cs +++ b/src/TaglibSharp.Tests/Images/GifExiftoolLongCommentTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TaglibSharp.Tests.Images.Validators; @@ -20,7 +22,7 @@ public void Test () true, new GifExiftoolLongCommentTestInvariantValidator (), NoModificationValidator.Instance, - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true), + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true), new CommentModificationValidator (long_comment_orig), new CommentModificationValidator (long_comment_orig, long_comment_test), new TagCommentModificationValidator (long_comment_orig, TagTypes.GifComment, true), diff --git a/src/TaglibSharp.Tests/Images/GifExiftoolTangled3Test.cs b/src/TaglibSharp.Tests/Images/GifExiftoolTangled3Test.cs index f1ab2f4d4..abc9f8b7e 100644 --- a/src/TaglibSharp.Tests/Images/GifExiftoolTangled3Test.cs +++ b/src/TaglibSharp.Tests/Images/GifExiftoolTangled3Test.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TaglibSharp.Tests.Images.Validators; @@ -19,7 +21,7 @@ public void Test () true, new GifExiftoolTangled3TestInvariantValidator (), NoModificationValidator.Instance, - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, false), + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, false), new CommentModificationValidator ("Created with GIMP"), new TagCommentModificationValidator ("Created with GIMP", TagTypes.GifComment, true), new RemoveMetadataValidator (TagTypes.GifComment) diff --git a/src/TaglibSharp.Tests/Images/ImageTagTests.cs b/src/TaglibSharp.Tests/Images/ImageTagTests.cs index 47e0f5bbe..bd92d612e 100644 --- a/src/TaglibSharp.Tests/Images/ImageTagTests.cs +++ b/src/TaglibSharp.Tests/Images/ImageTagTests.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.Image; @@ -20,7 +22,7 @@ public void TestXMPImageTag () Assert.IsNotNull (tag); Assert.AreEqual (null, tag.Comment, "Comment"); - Assert.AreEqual (new string[] { }, tag.Keywords, "Keywords"); + Assert.AreEqual (Array.Empty (), tag.Keywords, "Keywords"); Assert.AreEqual (0, tag.Rating, "Rating"); Assert.AreEqual (null, tag.DateTime, "DateTime"); Assert.AreEqual (ImageOrientation.None, tag.Orientation, "Orientation"); diff --git a/src/TaglibSharp.Tests/Images/JpegNikon1Bibble5Test.cs b/src/TaglibSharp.Tests/Images/JpegNikon1Bibble5Test.cs index 59476c249..bde51b6de 100644 --- a/src/TaglibSharp.Tests/Images/JpegNikon1Bibble5Test.cs +++ b/src/TaglibSharp.Tests/Images/JpegNikon1Bibble5Test.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/JpegNikon2Bibble5Test.cs b/src/TaglibSharp.Tests/Images/JpegNikon2Bibble5Test.cs index 48d496396..c178248c9 100644 --- a/src/TaglibSharp.Tests/Images/JpegNikon2Bibble5Test.cs +++ b/src/TaglibSharp.Tests/Images/JpegNikon2Bibble5Test.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/JpegOlympus2Test.cs b/src/TaglibSharp.Tests/Images/JpegOlympus2Test.cs index 628bea6cd..44568de3c 100644 --- a/src/TaglibSharp.Tests/Images/JpegOlympus2Test.cs +++ b/src/TaglibSharp.Tests/Images/JpegOlympus2Test.cs @@ -165,7 +165,7 @@ public void CheckXMP (File file) Assert.IsNotNull (tag, "tag"); - Assert.AreEqual (new string[] { }, tag.Keywords); + Assert.AreEqual (Array.Empty (), tag.Keywords); Assert.AreEqual ("OLYMPUS CORPORATION", tag.Make); Assert.AreEqual ("C5060WZ", tag.Model); Assert.AreEqual ("Adobe Photoshop Elements 4.0", tag.Software); diff --git a/src/TaglibSharp.Tests/Images/PefPentaxKd10Test.cs b/src/TaglibSharp.Tests/Images/PefPentaxKd10Test.cs index 5e6e2f9ee..e9cda2e5b 100644 --- a/src/TaglibSharp.Tests/Images/PefPentaxKd10Test.cs +++ b/src/TaglibSharp.Tests/Images/PefPentaxKd10Test.cs @@ -30,7 +30,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file) var imagetag = file.ImageTag; Assert.IsNotNull (imagetag); Assert.AreEqual (String.Empty, imagetag.Comment, "Comment"); - Assert.AreEqual (new string[] { }, imagetag.Keywords, "Keywords"); + Assert.AreEqual (Array.Empty (), imagetag.Keywords, "Keywords"); Assert.AreEqual (null, imagetag.Rating, "Rating"); Assert.AreEqual (TagLib.Image.ImageOrientation.LeftBottom, imagetag.Orientation, "Orientation"); Assert.AreEqual ("K10D Ver 1.31 ", imagetag.Software, "Software"); diff --git a/src/TaglibSharp.Tests/Images/RawLeicaDigilux2Test.cs b/src/TaglibSharp.Tests/Images/RawLeicaDigilux2Test.cs index 0ee373a0d..1d981e930 100644 --- a/src/TaglibSharp.Tests/Images/RawLeicaDigilux2Test.cs +++ b/src/TaglibSharp.Tests/Images/RawLeicaDigilux2Test.cs @@ -26,7 +26,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file) var imagetag = file.ImageTag; Assert.IsNotNull (imagetag); Assert.AreEqual (String.Empty, imagetag.Comment, "Comment"); - Assert.AreEqual (new string[] { }, imagetag.Keywords, "Keywords"); + Assert.AreEqual (Array.Empty (), imagetag.Keywords, "Keywords"); Assert.AreEqual (null, imagetag.Rating, "Rating"); Assert.AreEqual (TagLib.Image.ImageOrientation.TopLeft, imagetag.Orientation, "Orientation"); Assert.AreEqual (null, imagetag.Software, "Software"); diff --git a/src/TaglibSharp.Tests/Images/RecursiveIFDTest.cs b/src/TaglibSharp.Tests/Images/RecursiveIFDTest.cs index 8080296af..adb0239f4 100644 --- a/src/TaglibSharp.Tests/Images/RecursiveIFDTest.cs +++ b/src/TaglibSharp.Tests/Images/RecursiveIFDTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -259,7 +261,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file) Assert.IsNotNull (entry, "Entry 0x92D6 missing in IFD 0"); Assert.IsNotNull (entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; - var bytes = new byte[] { }; + var bytes = Array.Empty (); Assert.AreEqual (bytes, parsed_bytes); } // Thumbnail.0x0103 (Compression/Short/1) "6" diff --git a/src/TaglibSharp.Tests/Images/Rw2PanasonicG1Test.cs b/src/TaglibSharp.Tests/Images/Rw2PanasonicG1Test.cs index 011f6f8b4..b299446ce 100644 --- a/src/TaglibSharp.Tests/Images/Rw2PanasonicG1Test.cs +++ b/src/TaglibSharp.Tests/Images/Rw2PanasonicG1Test.cs @@ -33,7 +33,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file) var imagetag = file.ImageTag; Assert.IsNotNull (imagetag); Assert.AreEqual (String.Empty, imagetag.Comment, "Comment"); - Assert.AreEqual (new string[] { }, imagetag.Keywords, "Keywords"); + Assert.AreEqual (Array.Empty (), imagetag.Keywords, "Keywords"); Assert.AreEqual (null, imagetag.Rating, "Rating"); Assert.AreEqual (TagLib.Image.ImageOrientation.TopLeft, imagetag.Orientation, "Orientation"); Assert.AreEqual (null, imagetag.Software, "Software"); diff --git a/src/TaglibSharp.Tests/Images/TiffCanonBibble516BitTest.cs b/src/TaglibSharp.Tests/Images/TiffCanonBibble516BitTest.cs index 7095ab718..edd6a8595 100644 --- a/src/TaglibSharp.Tests/Images/TiffCanonBibble516BitTest.cs +++ b/src/TaglibSharp.Tests/Images/TiffCanonBibble516BitTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/TiffCanonBibble58BitTest.cs b/src/TaglibSharp.Tests/Images/TiffCanonBibble58BitTest.cs index 02a7ce1dc..29eb84a5f 100644 --- a/src/TaglibSharp.Tests/Images/TiffCanonBibble58BitTest.cs +++ b/src/TaglibSharp.Tests/Images/TiffCanonBibble58BitTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/TiffNikon1Bibble516BitTest.cs b/src/TaglibSharp.Tests/Images/TiffNikon1Bibble516BitTest.cs index 5ef80d4ba..e34ecd043 100644 --- a/src/TaglibSharp.Tests/Images/TiffNikon1Bibble516BitTest.cs +++ b/src/TaglibSharp.Tests/Images/TiffNikon1Bibble516BitTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/TiffNikon1Bibble58BitTest.cs b/src/TaglibSharp.Tests/Images/TiffNikon1Bibble58BitTest.cs index f09073a9a..4b8194376 100644 --- a/src/TaglibSharp.Tests/Images/TiffNikon1Bibble58BitTest.cs +++ b/src/TaglibSharp.Tests/Images/TiffNikon1Bibble58BitTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/TiffNikon2Bibble516BitTest.cs b/src/TaglibSharp.Tests/Images/TiffNikon2Bibble516BitTest.cs index 5ee7c2f72..84de643df 100644 --- a/src/TaglibSharp.Tests/Images/TiffNikon2Bibble516BitTest.cs +++ b/src/TaglibSharp.Tests/Images/TiffNikon2Bibble516BitTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/TiffNikon2Bibble58BitTest.cs b/src/TaglibSharp.Tests/Images/TiffNikon2Bibble58BitTest.cs index 57a46c795..21fcb6688 100644 --- a/src/TaglibSharp.Tests/Images/TiffNikon2Bibble58BitTest.cs +++ b/src/TaglibSharp.Tests/Images/TiffNikon2Bibble58BitTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.IFD; @@ -20,7 +22,7 @@ public void Test () new CommentModificationValidator (string.Empty), new TagCommentModificationValidator (null, TagTypes.TiffIFD, true), new TagCommentModificationValidator (null, TagTypes.XMP, true), - new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true) + new TagKeywordsModificationValidator (Array.Empty (), TagTypes.XMP, true) ); } } diff --git a/src/TaglibSharp.Tests/Images/Validators/KeywordsModificationValidator.cs b/src/TaglibSharp.Tests/Images/Validators/KeywordsModificationValidator.cs index d52645ab8..f61eeb246 100644 --- a/src/TaglibSharp.Tests/Images/Validators/KeywordsModificationValidator.cs +++ b/src/TaglibSharp.Tests/Images/Validators/KeywordsModificationValidator.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; @@ -12,7 +14,7 @@ public class KeywordsModificationValidator : IMetadataModificationValidator readonly string[] orig_keywords; readonly string[] test_keywords = { "keyword 1", "§$&§%", "99 dsf", "ഈ ヰᛥกツ" }; - public KeywordsModificationValidator () : this (new string[] { }) { } + public KeywordsModificationValidator () : this (Array.Empty ()) { } public KeywordsModificationValidator (string[] orig_keywords) { diff --git a/src/TaglibSharp.Tests/Images/Validators/TagKeywordsModificationValidator.cs b/src/TaglibSharp.Tests/Images/Validators/TagKeywordsModificationValidator.cs index 8198489c1..44900e2b7 100644 --- a/src/TaglibSharp.Tests/Images/Validators/TagKeywordsModificationValidator.cs +++ b/src/TaglibSharp.Tests/Images/Validators/TagKeywordsModificationValidator.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; @@ -12,7 +14,7 @@ public class TagKeywordsModificationValidator : KeywordsModificationValidator readonly bool tag_present; readonly TagTypes type; - public TagKeywordsModificationValidator (TagTypes type, bool tag_present) : this (new string[] { }, type, tag_present) { } + public TagKeywordsModificationValidator (TagTypes type, bool tag_present) : this (Array.Empty (), type, tag_present) { } public TagKeywordsModificationValidator (string[] orig_keywords, TagTypes type, bool tag_present) : base (orig_keywords) { diff --git a/src/TaglibSharp.Tests/TaggingFormats/ApeTest.cs b/src/TaglibSharp.Tests/TaggingFormats/ApeTest.cs index 2082f6b80..f2ece1d2a 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/ApeTest.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/ApeTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using Tag = TagLib.Ape.Tag; @@ -61,7 +63,7 @@ public void TestPerformers () } }); - tag.Performers = new string[0]; + tag.Performers = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -89,7 +91,7 @@ public void TestAlbumArtists () } }); - tag.AlbumArtists = new string[0]; + tag.AlbumArtists = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -117,7 +119,7 @@ public void TestComposers () } }); - tag.Composers = new string[0]; + tag.Composers = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -205,7 +207,7 @@ public void TestGenres () } }); - tag.Genres = new string[0]; + tag.Genres = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -501,7 +503,7 @@ public void TestPictures () } }); - tag.Pictures = new Picture[0]; + tag.Pictures = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); diff --git a/src/TaglibSharp.Tests/TaggingFormats/AsfTest.cs b/src/TaglibSharp.Tests/TaggingFormats/AsfTest.cs index 232e9db95..cdfd3a57a 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/AsfTest.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/AsfTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using File = TagLib.Asf.File; @@ -60,7 +62,7 @@ public void TestPerformers () } }); - file.Tag.Performers = new string[0]; + file.Tag.Performers = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -88,7 +90,7 @@ public void TestAlbumArtists () } }); - file.Tag.AlbumArtists = new string[0]; + file.Tag.AlbumArtists = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -116,7 +118,7 @@ public void TestComposers () } }); - file.Tag.Composers = new string[0]; + file.Tag.Composers = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -204,7 +206,7 @@ public void TestGenres () } }); - file.Tag.Genres = new string[0]; + file.Tag.Genres = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -500,7 +502,7 @@ public void TestPictures () } }); - file.Tag.Pictures = new Picture[0]; + file.Tag.Pictures = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); diff --git a/src/TaglibSharp.Tests/TaggingFormats/DivXTest.cs b/src/TaglibSharp.Tests/TaggingFormats/DivXTest.cs index c37229bf6..c7f112349 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/DivXTest.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/DivXTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; namespace TaglibSharp.Tests.TaggingFormats @@ -59,7 +61,7 @@ public void TestPerformers () Assert.IsFalse (tag.IsEmpty, "Still not empty"); Assert.AreEqual ("A123456789; B123456789; C12345", tag.JoinedPerformers); - tag.Performers = new string[0]; + tag.Performers = Array.Empty (); Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Performers.Length, "Again empty"); @@ -164,7 +166,7 @@ public void TestGenres () Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Genres.Length, "Still empty"); - tag.Genres = new string[0]; + tag.Genres = Array.Empty (); Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Genres.Length, "Again empty"); diff --git a/src/TaglibSharp.Tests/TaggingFormats/Id3V1Test.cs b/src/TaglibSharp.Tests/TaggingFormats/Id3V1Test.cs index 476d65332..5d4bbb052 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/Id3V1Test.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/Id3V1Test.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; namespace TaglibSharp.Tests.TaggingFormats @@ -59,7 +61,7 @@ public void TestPerformers () Assert.IsFalse (tag.IsEmpty, "Still not empty"); Assert.AreEqual ("A123456789; B123456789; C1234567", tag.JoinedPerformers); - tag.Performers = new string[0]; + tag.Performers = Array.Empty (); Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Performers.Length, "Again empty"); @@ -228,7 +230,7 @@ public void TestGenres () Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Genres.Length, "Still empty"); - tag.Genres = new string[0]; + tag.Genres = Array.Empty (); Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Genres.Length, "Again empty"); diff --git a/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs b/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs index 8b2ea676c..0cde3e5c7 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs @@ -1,4 +1,6 @@ using NUnit.Framework; + +using System; using System.Collections.Generic; using TagLib; using TagLib.Id3v2; @@ -68,7 +70,7 @@ public void TestPerformers () } }); - tag.Performers = new string[0]; + tag.Performers = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -99,7 +101,7 @@ public void TestAlbumArtists () } }); - tag.AlbumArtists = new string[0]; + tag.AlbumArtists = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -130,7 +132,7 @@ public void TestComposers () } }); - tag.Composers = new string[0]; + tag.Composers = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -237,7 +239,7 @@ public void TestGenres () } }); - tag.Genres = new string[0]; + tag.Genres = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -567,7 +569,7 @@ public void TestPictures () } }); - tag.Pictures = new Picture[0]; + tag.Pictures = Array.Empty (); TagTestWithSave (ref tag, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); diff --git a/src/TaglibSharp.Tests/TaggingFormats/InfoTagTest.cs b/src/TaglibSharp.Tests/TaggingFormats/InfoTagTest.cs index c5b7118e4..738c6f6c5 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/InfoTagTest.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/InfoTagTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; using TagLib.Riff; @@ -165,7 +167,7 @@ public void TestPerformers (StringType stringType) } }); - tag.Performers = new string[0]; + tag.Performers = Array.Empty (); TagTestWithSave (ref tag, delegate (TagLib.Riff.InfoTag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -198,7 +200,7 @@ public void TestAlbumArtists (StringType stringType) } }); - tag.AlbumArtists = new string[0]; + tag.AlbumArtists = Array.Empty (); TagTestWithSave (ref tag, delegate (TagLib.Riff.InfoTag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -231,7 +233,7 @@ public void TestComposers (StringType stringType) } }); - tag.Composers = new string[0]; + tag.Composers = Array.Empty (); TagTestWithSave (ref tag, delegate (TagLib.Riff.InfoTag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -304,7 +306,7 @@ public void TestGenres (StringType stringType) } }); - tag.Genres = new string[0]; + tag.Genres = Array.Empty (); TagTestWithSave (ref tag, delegate (TagLib.Riff.InfoTag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); diff --git a/src/TaglibSharp.Tests/TaggingFormats/MovieIdTagTest.cs b/src/TaglibSharp.Tests/TaggingFormats/MovieIdTagTest.cs index 2bd884dbf..b43d4b66a 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/MovieIdTagTest.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/MovieIdTagTest.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; @@ -61,7 +63,7 @@ public void TestPerformers () } }); - tag.Performers = new string[0]; + tag.Performers = Array.Empty (); TagTestWithSave (ref tag, delegate (TagLib.Riff.MovieIdTag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -124,7 +126,7 @@ public void TestGenres () } }); - tag.Genres = new string[0]; + tag.Genres = Array.Empty (); TagTestWithSave (ref tag, delegate (TagLib.Riff.MovieIdTag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); diff --git a/src/TaglibSharp.Tests/TaggingFormats/Mpeg4Test.cs b/src/TaglibSharp.Tests/TaggingFormats/Mpeg4Test.cs index dbc0ca5d6..61b16e41e 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/Mpeg4Test.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/Mpeg4Test.cs @@ -1,3 +1,5 @@ +using System; + using NUnit.Framework; using TagLib; @@ -61,7 +63,7 @@ public void TestPerformers () } }); - file.Tag.Performers = new string[0]; + file.Tag.Performers = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -89,7 +91,7 @@ public void TestAlbumArtists () } }); - file.Tag.AlbumArtists = new string[0]; + file.Tag.AlbumArtists = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -117,7 +119,7 @@ public void TestComposers () } }); - file.Tag.Composers = new string[0]; + file.Tag.Composers = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -205,7 +207,7 @@ public void TestGenres () } }); - file.Tag.Genres = new string[0]; + file.Tag.Genres = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -501,7 +503,7 @@ public void TestPictures () } }); - file.Tag.Pictures = new Picture[0]; + file.Tag.Pictures = Array.Empty (); TagTestWithSave (ref file, abst, delegate (Tag t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); diff --git a/src/TaglibSharp.Tests/TaggingFormats/XiphTest.cs b/src/TaglibSharp.Tests/TaggingFormats/XiphTest.cs index c103d1257..c33a64295 100644 --- a/src/TaglibSharp.Tests/TaggingFormats/XiphTest.cs +++ b/src/TaglibSharp.Tests/TaggingFormats/XiphTest.cs @@ -64,7 +64,7 @@ public void TestPerformers () } }); - tag.Performers = new string[0]; + tag.Performers = Array.Empty (); TagTestWithSave (ref tag, delegate (XiphComment t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -92,7 +92,7 @@ public void TestAlbumArtists () } }); - tag.AlbumArtists = new string[0]; + tag.AlbumArtists = Array.Empty (); TagTestWithSave (ref tag, delegate (XiphComment t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -120,7 +120,7 @@ public void TestComposers () } }); - tag.Composers = new string[0]; + tag.Composers = Array.Empty (); TagTestWithSave (ref tag, delegate (XiphComment t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -208,7 +208,7 @@ public void TestGenres () } }); - tag.Genres = new string[0]; + tag.Genres = Array.Empty (); TagTestWithSave (ref tag, delegate (XiphComment t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); @@ -496,7 +496,7 @@ public void TestPictures () Assert.IsTrue (!t.IsEmpty, "Value Set (IsEmpty): " + m); }); - tag.Pictures = new Picture[0]; + tag.Pictures = Array.Empty (); TagTestWithSave (ref tag, delegate (XiphComment t, string m) { Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m); diff --git a/src/TaglibSharp/Ape/Item.cs b/src/TaglibSharp/Ape/Item.cs index de65c3d9a..e96cf4dff 100644 --- a/src/TaglibSharp/Ape/Item.cs +++ b/src/TaglibSharp/Ape/Item.cs @@ -357,7 +357,7 @@ public override string ToString () public string[] ToStringArray () { if (Type == ItemType.Binary || text == null) - return new string[0]; + return Array.Empty (); return text; } diff --git a/src/TaglibSharp/Ape/Tag.cs b/src/TaglibSharp/Ape/Tag.cs index c3b631b6b..977b2363f 100644 --- a/src/TaglibSharp/Ape/Tag.cs +++ b/src/TaglibSharp/Ape/Tag.cs @@ -707,7 +707,7 @@ string GetItemAsString (string key) string[] GetItemAsStrings (string key) { Item item = GetItem (key); - return item != null ? item.ToStringArray () : new string[0]; + return item != null ? item.ToStringArray () : Array.Empty (); } /// diff --git a/src/TaglibSharp/Asf/Tag.cs b/src/TaglibSharp/Asf/Tag.cs index 84717ba22..aa7c41bea 100644 --- a/src/TaglibSharp/Asf/Tag.cs +++ b/src/TaglibSharp/Asf/Tag.cs @@ -430,7 +430,7 @@ static ByteVector PictureToData (IPicture picture) static string[] SplitAndClean (string s) { if (s == null || s.Trim ().Length == 0) - return new string[0]; + return Array.Empty (); string[] result = s.Split (';'); @@ -777,7 +777,7 @@ public override string[] Genres { string value = GetDescriptorString ("WM/Genre", "WM/GenreID", "Genre"); if (value == null || value.Trim ().Length == 0) - return new string[] { }; + return Array.Empty (); string[] result = value.Split (';'); diff --git a/src/TaglibSharp/CombinedTag.cs b/src/TaglibSharp/CombinedTag.cs index 009eb8faa..eca0b0d6e 100644 --- a/src/TaglibSharp/CombinedTag.cs +++ b/src/TaglibSharp/CombinedTag.cs @@ -349,7 +349,7 @@ public override string[] Performers { return value; } - return new string[] { }; + return Array.Empty (); } set { @@ -389,7 +389,7 @@ public override string[] PerformersSort { return value; } - return new string[] { }; + return Array.Empty (); } set { @@ -430,7 +430,7 @@ public override string[] PerformersRole { return value; } - return new string[] { }; + return Array.Empty (); } set { @@ -474,7 +474,7 @@ public override string[] AlbumArtistsSort { return value; } - return new string[] { }; + return Array.Empty (); } set { @@ -515,7 +515,7 @@ public override string[] AlbumArtists { return value; } - return new string[] { }; + return Array.Empty (); } set { @@ -554,7 +554,7 @@ public override string[] Composers { return value; } - return new string[] { }; + return Array.Empty (); } set { @@ -593,7 +593,7 @@ public override string[] ComposersSort { return value; } - return new string[] { }; + return Array.Empty (); } set { @@ -788,7 +788,7 @@ public override string[] Genres { return value; } - return new string[] { }; + return Array.Empty (); } set { diff --git a/src/TaglibSharp/Id3v1/Tag.cs b/src/TaglibSharp/Id3v1/Tag.cs index 444dda9b5..22cfd748e 100644 --- a/src/TaglibSharp/Id3v1/Tag.cs +++ b/src/TaglibSharp/Id3v1/Tag.cs @@ -330,7 +330,7 @@ public override string Title { /// public override string[] Performers { get { - return string.IsNullOrEmpty (artist) ? new string[0] : artist.Split (';'); + return string.IsNullOrEmpty (artist) ? Array.Empty () : artist.Split (';'); } set { artist = value != null ? string.Join (";", value) : string.Empty; @@ -402,7 +402,7 @@ public override string[] Genres { get { string genre_name = TagLib.Genres.IndexToAudio (genre); - return (genre_name != null) ? new [] { genre_name } : new string[0]; + return (genre_name != null) ? new [] { genre_name } : Array.Empty (); } set { genre = (value == null || value.Length == 0) ? diff --git a/src/TaglibSharp/Id3v2/Frames/SynchronizedLyricsFrame.cs b/src/TaglibSharp/Id3v2/Frames/SynchronizedLyricsFrame.cs index 4e9bc078a..efca75289 100644 --- a/src/TaglibSharp/Id3v2/Frames/SynchronizedLyricsFrame.cs +++ b/src/TaglibSharp/Id3v2/Frames/SynchronizedLyricsFrame.cs @@ -21,6 +21,7 @@ // USA // +using System; using System.Collections.Generic; namespace TagLib.Id3v2 @@ -42,7 +43,7 @@ public class SynchronisedLyricsFrame : Frame /// /// Contains the text. /// - SynchedText[] text = new SynchedText[0]; + SynchedText[] text = Array.Empty (); #endregion @@ -244,7 +245,7 @@ public string Language { /// public SynchedText[] Text { get { return text; } - set { text = value ?? (new SynchedText[0]); } + set { text = value ?? Array.Empty (); } } #endregion diff --git a/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs b/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs index 541adf2a7..7cdd648e2 100644 --- a/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs +++ b/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs @@ -382,7 +382,7 @@ public class TextInformationFrame : Frame /// /// Contains the text fields. /// - string[] text_fields = new string[0]; + string[] text_fields = Array.Empty (); /// /// Contains the raw data from the frame, or (); } } @@ -1158,7 +1158,7 @@ public override string[] Text { get { string[] text = base.Text; if (text.Length < 2) - return new string[0]; + return Array.Empty (); string[] new_text = new string[text.Length - 1]; for (int i = 0; i < new_text.Length; i++) diff --git a/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs b/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs index 3a7bee876..68ec00835 100644 --- a/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs +++ b/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs @@ -118,7 +118,7 @@ public class UrlLinkFrame : Frame /// /// Contains the text fields. /// - string[] text_fields = new string[0]; + string[] text_fields = Array.Empty (); /// /// Contains the raw data from the frame, or @@ -238,7 +238,7 @@ public virtual string[] Text { raw_data = null; text_fields = value != null ? (string[])value.Clone () : - new string[0]; + Array.Empty (); } } @@ -642,7 +642,7 @@ public override string[] Text { get { string[] text = base.Text; if (text.Length < 2) - return new string[0]; + return Array.Empty (); string[] new_text = new string[text.Length - 1]; for (int i = 0; i < new_text.Length; i++) diff --git a/src/TaglibSharp/Id3v2/Tag.cs b/src/TaglibSharp/Id3v2/Tag.cs index 1c3676ff7..709be8ea0 100644 --- a/src/TaglibSharp/Id3v2/Tag.cs +++ b/src/TaglibSharp/Id3v2/Tag.cs @@ -1022,7 +1022,7 @@ string[] GetTextAsArray (ByteVector ident) { var frame = TextInformationFrame.Get (this, ident, false); - return frame == null ? new string[0] : frame.Text; + return frame == null ? Array.Empty () : frame.Text; } /// @@ -1392,7 +1392,7 @@ public override string[] PerformersRole { var perfref = Performers; if (Performers == null) - return performers_role = new string[0]; + return performers_role = Array.Empty (); // Map the instruments to the performers @@ -1423,7 +1423,7 @@ public override string[] PerformersRole { } set { - performers_role = value ?? new string[0]; + performers_role = value ?? Array.Empty (); } } diff --git a/src/TaglibSharp/Image/CombinedImageTag.cs b/src/TaglibSharp/Image/CombinedImageTag.cs index 2cc862c14..313fec7fe 100644 --- a/src/TaglibSharp/Image/CombinedImageTag.cs +++ b/src/TaglibSharp/Image/CombinedImageTag.cs @@ -205,7 +205,7 @@ public override string[] Keywords { return value; } - return new string[] { }; + return Array.Empty (); } set { foreach (ImageTag tag in AllTags) diff --git a/src/TaglibSharp/Image/ImageTag.cs b/src/TaglibSharp/Image/ImageTag.cs index bf036e362..86fcb0db7 100644 --- a/src/TaglibSharp/Image/ImageTag.cs +++ b/src/TaglibSharp/Image/ImageTag.cs @@ -46,7 +46,7 @@ public abstract class ImageTag : Tag /// current instace. /// public virtual string[] Keywords { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } diff --git a/src/TaglibSharp/Matroska/Tag.cs b/src/TaglibSharp/Matroska/Tag.cs index 0fc3f7d0e..7c3bd1790 100644 --- a/src/TaglibSharp/Matroska/Tag.cs +++ b/src/TaglibSharp/Matroska/Tag.cs @@ -836,7 +836,7 @@ public override string[] Genres { string value = GetString ("GENRE"); if (value == null || value.Trim ().Length == 0) - return new string[] { }; + return Array.Empty (); string[] result = value.Split (';'); diff --git a/src/TaglibSharp/Matroska/Tags.cs b/src/TaglibSharp/Matroska/Tags.cs index a2eead083..f0c6a499c 100644 --- a/src/TaglibSharp/Matroska/Tags.cs +++ b/src/TaglibSharp/Matroska/Tags.cs @@ -36,7 +36,7 @@ public class Tags : Collection #region Private fields/Properties // Store the Attachments - Attachment[] attachments = new Attachment[0]; + Attachment[] attachments = Array.Empty (); readonly List _Tracks; @@ -273,7 +273,7 @@ public Attachment[] Attachments { } set { if (value == null) { - if (attachments.Length > 0) attachments = new Attachment[0]; + if (attachments.Length > 0) attachments = Array.Empty (); } else { attachments = value; } diff --git a/src/TaglibSharp/Ogg/GroupedComment.cs b/src/TaglibSharp/Ogg/GroupedComment.cs index 80f2a9004..d5c1e8513 100644 --- a/src/TaglibSharp/Ogg/GroupedComment.cs +++ b/src/TaglibSharp/Ogg/GroupedComment.cs @@ -312,7 +312,7 @@ public override string[] Performers { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].Performers = value; } } @@ -344,7 +344,7 @@ public override string[] PerformersSort { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].PerformersSort = value; } } @@ -374,7 +374,7 @@ public override string[] PerformersRole { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].PerformersRole = value; } } @@ -407,7 +407,7 @@ public override string[] AlbumArtists { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].AlbumArtists = value; } } @@ -442,7 +442,7 @@ public override string[] AlbumArtistsSort { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].AlbumArtistsSort = value; } @@ -474,7 +474,7 @@ public override string[] Composers { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].Composers = value; } } @@ -505,7 +505,7 @@ public override string[] ComposersSort { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].ComposersSort = value; } } @@ -629,7 +629,7 @@ public override string[] Genres { return value; } - return new string[] { }; + return Array.Empty (); } set { if (tags.Count > 0) tags[0].Genres = value; } } @@ -1445,7 +1445,7 @@ public override double ReplayGainAlbumPeak { /// public override IPicture[] Pictures { get { - IPicture[] output = new IPicture[0]; + IPicture[] output = Array.Empty (); foreach (XiphComment tag in tags) if (tag != null && output.Length == 0) output = tag.Pictures; diff --git a/src/TaglibSharp/Ogg/Paginator.cs b/src/TaglibSharp/Ogg/Paginator.cs index 6683b7bb1..507bf3edd 100644 --- a/src/TaglibSharp/Ogg/Paginator.cs +++ b/src/TaglibSharp/Ogg/Paginator.cs @@ -162,7 +162,7 @@ public Page[] Paginate (out int change) if (pages_read == 0) { change = 0; - return new Page[0]; + return Array.Empty (); } int count = pages_read; diff --git a/src/TaglibSharp/Ogg/XiphComment.cs b/src/TaglibSharp/Ogg/XiphComment.cs index dd1f98e89..57314a652 100644 --- a/src/TaglibSharp/Ogg/XiphComment.cs +++ b/src/TaglibSharp/Ogg/XiphComment.cs @@ -77,7 +77,7 @@ public class XiphComment : Tag, IEnumerable /// /// Cached empty pictures array. /// - static readonly IPicture[] EMPTY_PICTURES = new IPicture[0]; + static readonly IPicture[] EMPTY_PICTURES = Array.Empty (); #endregion @@ -143,7 +143,7 @@ public string[] GetField (string key) EnsurePictureFieldsClean (key); if (!field_list.ContainsKey (key)) - return new string[0]; + return Array.Empty (); return (string[])field_list[key].Clone (); } @@ -1684,7 +1684,7 @@ public override void Clear () field_list.Clear (); // clear pictures - pictures = new IPicture[0]; + pictures = Array.Empty (); picture_fields_dirty = false; } diff --git a/src/TaglibSharp/Properties.cs b/src/TaglibSharp/Properties.cs index befda88e9..7e33d1996 100644 --- a/src/TaglibSharp/Properties.cs +++ b/src/TaglibSharp/Properties.cs @@ -45,7 +45,7 @@ public class Properties : IAudioCodec, IVideoCodec, IPhotoCodec /// /// Contains the codecs. /// - readonly ICodec[] codecs = new ICodec[0]; + readonly ICodec[] codecs = Array.Empty (); /// /// Contains the duration. diff --git a/src/TaglibSharp/Riff/DivXTag.cs b/src/TaglibSharp/Riff/DivXTag.cs index 018d19c2f..c6337aef8 100644 --- a/src/TaglibSharp/Riff/DivXTag.cs +++ b/src/TaglibSharp/Riff/DivXTag.cs @@ -289,7 +289,7 @@ public override string Title { /// public override string[] Performers { get { - return string.IsNullOrEmpty (artist) ? new string[0] : artist.Split (';'); + return string.IsNullOrEmpty (artist) ? Array.Empty () : artist.Split (';'); } set { artist = value != null ? string.Join (";", value) : string.Empty; @@ -338,7 +338,7 @@ public override string[] Genres { get { string genre_name = TagLib.Genres.IndexToVideo (genre); - return (genre_name != null) ? new[] { genre_name } : new string[0]; + return (genre_name != null) ? new[] { genre_name } : Array.Empty (); } set { genre = (value != null && value.Length > 0) ? diff --git a/src/TaglibSharp/Riff/File.cs b/src/TaglibSharp/Riff/File.cs index db2c6a6b3..a2e782d3a 100644 --- a/src/TaglibSharp/Riff/File.cs +++ b/src/TaglibSharp/Riff/File.cs @@ -448,7 +448,7 @@ void Read (bool read_tags, ReadStyle style, out uint riff_size, out long tag_sta long length = Length; uint size = 0; TimeSpan duration = TimeSpan.Zero; - ICodec[] codecs = new ICodec[0]; + ICodec[] codecs = Array.Empty (); // Read until there are less than 8 bytes to read. do { diff --git a/src/TaglibSharp/Tag.cs b/src/TaglibSharp/Tag.cs index 9e5c00b8b..bd6a8a1da 100644 --- a/src/TaglibSharp/Tag.cs +++ b/src/TaglibSharp/Tag.cs @@ -277,7 +277,7 @@ public virtual string Description { /// choice they may make. /// public virtual string[] Performers { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -299,7 +299,7 @@ public virtual string[] Performers { /// /// public virtual string[] PerformersSort { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -324,7 +324,7 @@ public virtual string[] PerformersSort { /// /// public virtual string[] PerformersRole { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -355,7 +355,7 @@ public virtual string[] PerformersRole { /// name. For example, "The Beatles". /// public virtual string[] AlbumArtists { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -387,7 +387,7 @@ public virtual string[] AlbumArtists { /// name. For example, "Beatles, The". /// public virtual string[] AlbumArtistsSort { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -406,7 +406,7 @@ public virtual string[] AlbumArtistsSort { /// media. /// public virtual string[] Composers { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -430,7 +430,7 @@ public virtual string[] Composers { /// For example, "McCartney, Paul". /// public virtual string[] ComposersSort { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -524,7 +524,7 @@ public virtual string Comment { /// genres as used by DivX. /// public virtual string[] Genres { - get { return new string[] { }; } + get { return Array.Empty (); } set { } } @@ -1094,7 +1094,7 @@ public virtual string Length { /// band, the recording studio, the concert, etc. /// public virtual IPicture[] Pictures { - get { return new IPicture[] { }; } + get { return Array.Empty (); } set { } } diff --git a/src/TaglibSharp/Xmp/XmpTag.cs b/src/TaglibSharp/Xmp/XmpTag.cs index 5c9fa548a..79f73d874 100644 --- a/src/TaglibSharp/Xmp/XmpTag.cs +++ b/src/TaglibSharp/Xmp/XmpTag.cs @@ -1104,7 +1104,7 @@ public override string Comment { /// current instace. /// public override string[] Keywords { - get { return GetCollectionNode (DC_NS, "subject") ?? new string[] { }; } + get { return GetCollectionNode (DC_NS, "subject") ?? Array.Empty (); } set { SetCollectionNode (DC_NS, "subject", value, XmpNodeType.Bag); } } From fa2e0ab42c2362ce6a8f1193183dd49472fa398f Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Fri, 29 Jul 2022 19:23:33 -0600 Subject: [PATCH 2/3] Use StringBuilder.Append(char) instead of (string) CA1834: Use StringBuilder.Append(char) for single character strings https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1834 --- src/TaglibSharp/Id3v2/Frames/AttachmentFrame.cs | 2 +- src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs | 4 ++-- src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs | 2 +- src/TaglibSharp/Id3v2/Tag.cs | 4 ++-- src/TaglibSharp/Mpeg/AudioHeader.cs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/TaglibSharp/Id3v2/Frames/AttachmentFrame.cs b/src/TaglibSharp/Id3v2/Frames/AttachmentFrame.cs index 7bd1cd3ab..98d8bc2ae 100644 --- a/src/TaglibSharp/Id3v2/Frames/AttachmentFrame.cs +++ b/src/TaglibSharp/Id3v2/Frames/AttachmentFrame.cs @@ -506,7 +506,7 @@ public override string ToString () if (string.IsNullOrEmpty (Description)) { builder.Append (Description); - builder.Append (" "); + builder.Append (' '); } builder.AppendFormat (System.Globalization.CultureInfo.InvariantCulture, "[{0}] {1} bytes", MimeType, Data.Count); diff --git a/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs b/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs index 7cdd648e2..64c4dc1de 100644 --- a/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs +++ b/src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs @@ -960,7 +960,7 @@ protected override ByteVector RenderFields (byte version) StringBuilder data = new StringBuilder (); foreach (string s in text) { if (!prev_value_indexed) { - data.Append (";").Append (s); + data.Append (';').Append (s); continue; } @@ -1192,7 +1192,7 @@ public override string[] Text { /// public override string ToString () { - return new StringBuilder ().Append ("[") + return new StringBuilder ().Append ('[') .Append (Description) .Append ("] ") .Append (base.ToString ()).ToString (); diff --git a/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs b/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs index 68ec00835..dea9a0098 100644 --- a/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs +++ b/src/TaglibSharp/Id3v2/Frames/UrlLinkFrame.cs @@ -677,7 +677,7 @@ public override string[] Text { /// public override string ToString () { - return new StringBuilder ().Append ("[") + return new StringBuilder ().Append ('[') .Append (Description) .Append ("] ") .Append (base.ToString ()).ToString (); diff --git a/src/TaglibSharp/Id3v2/Tag.cs b/src/TaglibSharp/Id3v2/Tag.cs index 709be8ea0..5fd66a534 100644 --- a/src/TaglibSharp/Id3v2/Tag.cs +++ b/src/TaglibSharp/Id3v2/Tag.cs @@ -979,14 +979,14 @@ protected void Parse (ByteVector data, File file, long position, ReadStyle style if (tdat != null) { string tdat_text = tdat.ToString (); if (tdat_text.Length == 4) { - tdrc_text.Append ("-").Append (tdat_text, 0, 2).Append ("-").Append (tdat_text, 2, 2); + tdrc_text.Append ('-').Append (tdat_text, 0, 2).Append ('-').Append (tdat_text, 2, 2); // Add the time if (time != null) { string time_text = time.ToString (); if (time_text.Length == 4) - tdrc_text.Append ("T").Append (time_text, 0, 2).Append (":").Append (time_text, 2, 2); + tdrc_text.Append ('T').Append (time_text, 0, 2).Append (':').Append (time_text, 2, 2); RemoveFrames (FrameType.TIME); } diff --git a/src/TaglibSharp/Mpeg/AudioHeader.cs b/src/TaglibSharp/Mpeg/AudioHeader.cs index d18ea77d4..3711d0366 100644 --- a/src/TaglibSharp/Mpeg/AudioHeader.cs +++ b/src/TaglibSharp/Mpeg/AudioHeader.cs @@ -488,10 +488,10 @@ public string Description { builder.Append ("MPEG Version "); switch (Version) { case Version.Version1: - builder.Append ("1"); + builder.Append ('1'); break; case Version.Version2: - builder.Append ("2"); + builder.Append ('2'); break; case Version.Version25: builder.Append ("2.5"); From e674c3ad5e254dbe8564861a5805844f1e5f0988 Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Fri, 29 Jul 2022 19:24:41 -0600 Subject: [PATCH 3/3] Use Length/Count instead of Enumerable.Count where possible CA1829: Use Length/Count property instead of Enumerable.Count method https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1829 --- src/TaglibSharp.Tests/FileFormats/Id3V2FormatTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TaglibSharp.Tests/FileFormats/Id3V2FormatTest.cs b/src/TaglibSharp.Tests/FileFormats/Id3V2FormatTest.cs index 4c1b7787a..5eefcbb33 100644 --- a/src/TaglibSharp.Tests/FileFormats/Id3V2FormatTest.cs +++ b/src/TaglibSharp.Tests/FileFormats/Id3V2FormatTest.cs @@ -159,7 +159,7 @@ public void TestPicturesAreCopied () file.Tag.Pictures = new[] { picture }; file.Save (); - Assert.IsTrue (file.Tag.Pictures.Count () == 1, "File should start with 1 picture"); + Assert.IsTrue (file.Tag.Pictures.Length == 1, "File should start with 1 picture"); // Now construct a new tag with a title, APIC and GEOB frame @@ -187,12 +187,12 @@ public void TestPicturesAreCopied () tag.CopyTo (file.Tag, false); Assert.AreEqual ("MP3 title", file.Tag.Title, "Title shouldn't be copied if overwrite=false"); - Assert.AreEqual (1, file.Tag.Pictures.Count (), "GEOB/APIC frames shouldn't be copied if overwrite=false"); + Assert.AreEqual (1, file.Tag.Pictures.Length, "GEOB/APIC frames shouldn't be copied if overwrite=false"); tag.CopyTo (file.Tag, true); Assert.AreEqual (tag.Title, file.Tag.Title, "Title wasn't copied"); - Assert.AreEqual (tag.Pictures.Count (), file.Tag.Pictures.Count (), "GEOB/APIC frames weren't copied"); + Assert.AreEqual (tag.Pictures.Length, file.Tag.Pictures.Length, "GEOB/APIC frames weren't copied"); } } }