refactor: remove redundant null checks

This commit is contained in:
yyc12345 committed 2026-10-22 20:48:13 +08:00
1 parent c0c6e0a38f
commit 14b938ea67
4 files changed
-28

No files matched your search

-12
View File
@@ -231,18 +231,6 @@ public sealed class FilenameParserTests {
#endregion #endregion
#region Argument validation
/// <summary>
/// Verifies that a null input is rejected.
/// </summary>
[TestMethod]
public void ThrowsForNullInput() {
Assert.Throws<ArgumentNullException>(() => FilenameParser.Parse(null!));
}
#endregion
/// <summary> /// <summary>
/// Parses the input and asserts all three resulting fields. /// Parses the input and asserts all three resulting fields.
/// </summary> /// </summary>
-9
View File
@@ -114,15 +114,6 @@ public sealed class RenameFormatsTests {
AssertStem(RenameFormat.ArtistFirst, " ", "Title", "\t", "Title"); AssertStem(RenameFormat.ArtistFirst, " ", "Title", "\t", "Title");
} }
/// <summary>
/// Verifies that a null title is rejected.
/// </summary>
[TestMethod]
public void ThrowsForNullTitle() {
Assert.Throws<ArgumentNullException>(
() => RenameFormats.GenerateStem(RenameFormat.ArtistFirst, "Artist", null!, "Live"));
}
#endregion #endregion
/// <summary> /// <summary>
-4
View File
@@ -109,10 +109,6 @@ public static class RenameFormats {
/// Whitespace-only optional fields are treated as missing. /// Whitespace-only optional fields are treated as missing.
/// </remarks> /// </remarks>
public static string GenerateStem(RenameFormat format, string artist, string title, string comment) { public static string GenerateStem(RenameFormat format, string artist, string title, string comment) {
ArgumentNullException.ThrowIfNull(artist);
ArgumentNullException.ThrowIfNull(title);
ArgumentNullException.ThrowIfNull(comment);
RenameFormatDefinition definition = GetDefinition(format); RenameFormatDefinition definition = GetDefinition(format);
bool hasArtist = !string.IsNullOrWhiteSpace(artist); bool hasArtist = !string.IsNullOrWhiteSpace(artist);
bool hasComment = !string.IsNullOrWhiteSpace(comment); bool hasComment = !string.IsNullOrWhiteSpace(comment);
-3
View File
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
@@ -22,8 +21,6 @@ public static class FilenameParser {
/// When no hyphen or more than one hyphen remains, the artist is empty and the whole text is the title. /// When no hyphen or more than one hyphen remains, the artist is empty and the whole text is the title.
/// </remarks> /// </remarks>
public static FilenameParseResult Parse(string fileNameWithoutExtension) { public static FilenameParseResult Parse(string fileNameWithoutExtension) {
ArgumentNullException.ThrowIfNull(fileNameWithoutExtension);
string source = fileNameWithoutExtension; string source = fileNameWithoutExtension;
string comment = string.Empty; string comment = string.Empty;