While debugging the application (on a serious note) or doing code review sometimes if there is a string not-null or not-empty validation check it's obvious we may ignore those negate condition (!).
for example
if (!string.IsNullOrWhiteSpace(inputString)) { // do someting here }
To ignore these we generally adopt a rule to instead checking with negate condition use the (== false)
for example
if (string.IsNullOrWhiteSpace(inputString) == false) { // do someting here }
Isn't it's better to use StringUtility methods with all the possible string validation check in one place and use them in multiple projects as-is.
Some of the frequently used utility methods.
public static bool AreTrimEqual(string input1, string input2) { return string.Equals(input1?.Trim(), input2?.Trim(), StringComparison.InvariantCultureIgnoreCase); } public static string ToTitleCase(string title) { var cultureInfo = Thread.CurrentThread.CurrentCulture; var textInfo = cultureInfo.TextInfo; return textInfo.ToTitleCase(title); }
An exhaustive list can be found here.
Comments
Post a Comment