mardi 18 mai 2021

How do I reduce lines of code for null and empty string validation for API methods? [closed]

At the moment, I manually validate this way for 10 properties. Here I show only 3 properties.

if (string.IsNullOrEmpty(account.Name))
{
    return BadRequest("Name is required");
}

if (string.IsNullOrEmpty(account.Nationality))
{
    return BadRequest("Nationality is required");
}


if (string.IsNullOrEmpty(account.Phone))
{
    return BadRequest("Phone is required");
}

I believe there is a better way to refactor the code to reduce lines of code for API validation.

Aucun commentaire:

Enregistrer un commentaire