我可以使用re-sharper从对象初始值设定项中提取构造函数方法

时间:2015-10-18 22:30:01

标签: constructor refactoring resharper

例如我有这段代码

var person = new HighrisePerson()
{
    FirstName = firstName,
    ContactData = new HighriseContactData()
    {
        EmailAddresses = new List<HighriseEmailAddress>
        {
            new HighriseEmailAddress
            {
                Address = email,
                Location = "Work"
            }
        }
    }
};

我想重构一下:

var person = new HighrisePerson(firstName, email)

我希望这个构造函数添加到我的HighrisePerson Class

public HighrisePerson(string firstName, string email)
{
    FirstName = firstName,
    ContactData = new HighriseContactData()
    {
        EmailAddresses = new List<HighriseEmailAddress>
        {
            new HighriseEmailAddress
            {
                Address = email,
                Location = "Work"
            }
        }
    }
};

0 个答案:

没有答案