是否有从参数的现有方法自动生成poco类的简短方法?
public void RegisterUser(string userName, string fullName,
string tel, string mobile, string website, string address, string blah){
//--
}
从这个方法我应该能够自动生成我的类,如下所示:
class UserRegisterDetail{
public string UserName {get;set;}
public string FullName {get;set;}
public string Tel {get;set;}
public string Mobile {get;set;}
public string Website {get;set;}
public string Address {get;set;}
public string Blah {get;set;}
}
我使用resharper并重新分解但我无法生成简单的poco类。
更新
使用"从参数中提取类"选项生成以下内容:
public class RegisterUserParams
{
private string userName;
private string email;
private string fullName;
private string jobTitle;
private string department;
private string tel;
private string mobile;
private string switchboard;
private string fax;
private string address1;
private string address2;
private string address3;
public RegisterUserParams(string userName, string email, string fullName, string jobTitle, string department, string tel, string mobile, string switchboard, string fax, string address1, string address2, string address3 )
{
this.userName = userName;
this.email = email;
this.fullName = fullName;
this.jobTitle = jobTitle;
this.department = department;
this.tel = tel;
this.mobile = mobile;
this.switchboard = switchboard;
this.fax = fax;
this.address1 = address1;
this.address2 = address2;
this.address3 = address3;
}
public string UserName
{
get { return userName; }
}
public string Email
{
get { return email; }
}
public string FullName
{
get { return fullName; }
}
public string JobTitle
{
get { return jobTitle; }
}
public string Department
{
get { return department; }
}
public string Tel
{
get { return tel; }
}
public string Mobile
{
get { return mobile; }
}
public string Switchboard
{
get { return switchboard; }
}
public string Fax
{
get { return fax; }
}
public string Address1
{
get { return address1; }
}
public string Address2
{
get { return address2; }
}
public string Address3
{
get { return address3; }
}
}
答案 0 :(得分:0)
在我看来,您应该只创建具有所需属性的类作为参数,并将其实例作为参数传递。比拥有这么多参数的方法更好。
例如:
public void RegisterUser(UserRegisterDetail pInstanceOfMyClass)
{ ... }
在UserRegisterDetail中,您要使用要传递的属性。