views:

77

answers:

3

Is there any way to automatically create the constructor for a class based on the properties in the class like Eclipse does? (Without getting ReSharper). I'm using Visual Studio 2008 (C#).

If this is a duplicate, please link (I tried searching).

A: 

None that I am aware of.

Femaref
+2  A: 

No. There is the ctor snippet(not quite what you were looking for), or you can create your macro. Possibly check out Productivity macros for C#. And since you don't like ReSharper, you can use CodeRush.

Yuriy Faktorovich
Just for clarity, I am not anti-ReSharper. I just can't get it on this machine now, so I was hoping there was a built in way. That CodeRush example is exactly what I was thinking.
Awaken
+1  A: 

you can use object initializer instead of having created a constructor, if you're using C# 3.0.

Referring code that I found in some example.

   class Program
   {
      public class Student
      {
         public string firstName;
         public string lastName;
      }
      public class ScienceClass
      {
         public Student Student1, Student2, Student3;
      }
      static void Main(string[] args)
      {
         var student1 = new Student{firstName = "Bruce",
                                    lastName  = "Willis"};
         var student2 = new Student{firstName = "George",
                                    lastName  = "Clooney"};
         var student3 = new Student{firstName = "James",
                                    lastName  = "Cameron"};
         var sClass = new ScienceClass{Student1 = student1,
                                       Student2 = student2,
                                       Student3 = student3};
      }
   }
this. __curious_geek