diff --git a/csharp/Pehape/Pehape.csproj b/csharp/Pehape/Pehape.csproj index aa23382..ff342aa 100644 --- a/csharp/Pehape/Pehape.csproj +++ b/csharp/Pehape/Pehape.csproj @@ -1,7 +1,7 @@  - net6.0 + net9.0 enable False latest-all diff --git a/csharp/Pehape/String/Explode.cs b/csharp/Pehape/String/Explode.cs index da7a46f..d1fc805 100644 --- a/csharp/Pehape/String/Explode.cs +++ b/csharp/Pehape/String/Explode.cs @@ -16,7 +16,7 @@ public static partial class PHP { /// An array of strings. public static string[] Explode(string? separator, string str, int? limit = null) { if (separator is "") throw new ArgumentException("Separator cannot be empty.", nameof(separator)); - if (str is null) throw new ArgumentNullException(nameof(str)); + ArgumentNullException.ThrowIfNull(str); return limit switch { null => str.Split(separator), > 0 => str.Split(separator).Take(limit.Value).ToArray(), @@ -37,7 +37,7 @@ public static string[] Explode(string? separator, string str, int? limit = null) /// one element is returned. /// An array of strings. public static string[] Explode(char separator, string str, int? limit = null) { - if (str is null) throw new ArgumentNullException(nameof(str)); + ArgumentNullException.ThrowIfNull(str); return limit switch { null => str.Split(separator), > 0 => str.Split(separator).Take(limit.Value).ToArray(), diff --git a/csharp/Pehape/String/Levenshtein.cs b/csharp/Pehape/String/Levenshtein.cs index 1907ce2..68f33d6 100644 --- a/csharp/Pehape/String/Levenshtein.cs +++ b/csharp/Pehape/String/Levenshtein.cs @@ -16,8 +16,8 @@ public static partial class PHP { public static int Levenshtein(string string1, string string2, int insertCost = 1, int replaceCost = 1, int deleteCost = 1) { // Ported from https://github.com/php/php-src/blob/master/ext/standard/levenshtein.c - if (string1 is null) throw new ArgumentNullException(nameof(string1)); - if (string2 is null) throw new ArgumentNullException(nameof(string2)); + ArgumentNullException.ThrowIfNull(string1); + ArgumentNullException.ThrowIfNull(string2); if (insertCost < 0) throw new ArgumentException("InsertCost cannot be negative.", nameof(insertCost)); if (replaceCost < 0) throw new ArgumentException("ReplaceCost cannot be negative.", nameof(replaceCost)); if (deleteCost < 0) throw new ArgumentException("DeleteCost cannot be negative.", nameof(deleteCost)); @@ -28,7 +28,7 @@ public static int Levenshtein(string string1, string string2, int insertCost = 1 Span p1 = stackalloc int[string2.Length + 1]; Span p2 = stackalloc int[string2.Length + 1]; - bool swap = false; + var swap = false; for (var i2 = 0; i2 <= string2.Length; i2++) { p1[i2] = i2 * insertCost; @@ -42,7 +42,7 @@ public static int Levenshtein(string string1, string string2, int insertCost = 1 if (c1 < c0) { c0 = c1; } - int c2 = (swap ? p1 : p2)[i2] + insertCost; + var c2 = (swap ? p1 : p2)[i2] + insertCost; if (c2 < c0) { c0 = c2; } diff --git a/csharp/Pehape/String/StrRot13.cs b/csharp/Pehape/String/StrRot13.cs index b2f0fcd..44f3f56 100644 --- a/csharp/Pehape/String/StrRot13.cs +++ b/csharp/Pehape/String/StrRot13.cs @@ -14,10 +14,10 @@ public static partial class PHP { /// The input string. /// Returns the ROT13 version of the given string. public static string StrRot13(string str) { - if (str is null) throw new ArgumentNullException(nameof(str)); + ArgumentNullException.ThrowIfNull(str); var buffer = new StringBuilder(); - foreach (char ch in str) { + foreach (var ch in str) { buffer.Append((char)(ch switch { >= 'a' and <= 'z' => ch > 'm' ? ch - 13 : ch + 13, >= 'A' and <= 'Z' => ch > 'M' ? ch - 13 : ch + 13,