1

Is there any short way of auto generating poco class from an existing method with parameters?

 public void RegisterUser(string userName, string fullName, 
string tel, string mobile, string website, string address, string blah){
    //--
    }

from this method I should be able to auto generate my class as below:

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;}
}

I use resharper and re-factoring but I cannot generate the simple poco class.

Update:

Using "Extract class from parameters" option generates the following:

    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; }
            }         
        }
akd
  • 6,538
  • 16
  • 70
  • 112
  • 1
    Have you tried the "Extract class from Parameters" refactoring? BTW in C#, it's _POCO_, not pojo. – D Stanley Mar 22 '16 at 13:03
  • 1
    Well thats the reason I am trying to automatically generate poco class to pass the object rather than passing too many parameters – akd Mar 22 '16 at 13:17
  • I did try "Extract class from Parameters" but it does generate a class with default constructor and fields that I have updated in the question – akd Mar 22 '16 at 13:20

1 Answers1

0

It would seem to me that you should just create the class with the properties you want as parameters and pass an instance of it as the parameter. Better than having so many parameters for the method.

eg:

public void RegisterUser(UserRegisterDetail pInstanceOfMyClass)
{ ... }

Where UserRegisterDetail is you class with those properties you want to pass.

Kixoka
  • 989
  • 4
  • 15
  • 37