11// Copyright Subatomix Research Inc.
22// SPDX-License-Identifier: MIT
33
4- using System . Diagnostics . CodeAnalysis ;
5- using System . Text ;
6-
74namespace PSql . Deploy ;
85
96/// <summary>
@@ -26,7 +23,7 @@ public static bool IsNullOrEmpty([NotNullWhen(false)] this string? s)
2623 => string . IsNullOrEmpty ( s ) ;
2724
2825 /// <summary>
29- /// Replaces an empty string with <see langword="null"/>.
26+ /// Replaces the string with <see langword="null"/> if it is empty .
3027 /// </summary>
3128 /// <param name="s">
3229 /// The string to transform.
@@ -36,7 +33,28 @@ public static bool IsNullOrEmpty([NotNullWhen(false)] this string? s)
3633 /// <paramref name="s"/> otherwise.
3734 /// </returns>
3835 public static string ? NullIfEmpty ( this string ? s )
39- => string . IsNullOrEmpty ( s ) ? null : s ;
36+ => s . NullIf ( string . Empty ) ;
37+
38+ /// <summary>
39+ /// Replaces the string with <see langword="null"/> if it is equal to the
40+ /// specified string.
41+ /// </summary>
42+ /// <param name="s">
43+ /// The string to transform.
44+ /// </param>
45+ /// <param name="nullish">
46+ /// The string against which to compare <paramref name="s"/>.
47+ /// </param>
48+ /// <returns>
49+ /// <see langword="null"/>
50+ /// if <paramref name="s"/> is equal to <paramref name="nullish"/>;
51+ /// <paramref name="s"/>
52+ /// otherwise.
53+ /// </returns>
54+ /// This method performs a case-sensitive ordinal comparison.
55+ /// <remarks>
56+ public static string ? NullIf ( this string ? s , string ? nullish )
57+ => s == nullish ? null : s ;
4058
4159 /// <summary>
4260 /// Escapes the string for inclusing in a SQL string literal.
0 commit comments