In my method I have something like this:
returnValue = null;
if (!string.IsNullOrEmpty(pa.Phone))
{
if (pa.Length != 10 && member == Schema.Phone.Name)
{
returnValue = new stuff;
}
}
if (!string.IsNullOrEmpty(pa.OtherPhone))
{
if (pa.OtherPhone.Length != 10 && member == Schema.OtherPhone.Name)
{
returnValue = new stuff;
}
}
if (!string.IsNullOrEmpty(pa.Fax))
{
if (pa.Fax.Length != 10 && member == Schema.Fax.Name)
{
returnValue = new stuff
}
}
// even more similar ifs...
// at the end of method: return returnValue;
How can I refactor this logic? Note that new stuff is always the same for all the if
s.
Pa.Phone.Length
rather thanPa.Length
? \$\endgroup\$pa
andmember
might be. Alsonew stuff
should probably benew Stuff();
...and then we can help you come up with a more descriptive title ;) \$\endgroup\$