在我的方法中,我有类似的东西:
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;
我如何重构这个逻辑?
请注意,所有new stuff
ifs
始终相同