重构返回值的逻辑

时间:2014-04-29 19:10:19

标签: c#

在我的方法中,我有类似的东西:

        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始终相同

0 个答案:

没有答案