"To handle both null and empty string scenarios, use IsEmpty / HasValue instead"
You can avoid unnecessary clutter in your code by using IsEmpty or HasValue instead of string.IsNullOrEmpty()
or string.IsNullOrWhiteSpace()
.
public static void MyMethod(string myParam)
{
if (string.IsNullOrEmpty(myParam) || string.IsNullOrWhiteSpace(myParam))
{
...
}
}
should be 🡻
public static void MyMethod(string myParam)
{
if (myParam.TrimOrEmpty().IsEmpty())
{
...
}
}
If your logic applies to null, but not empty string, then change the condition to ReferenceEquals.
if (token != null)
{
...
}
should be 🡻
if (! (token is null))
{
...
}