Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically generate c# class

I often find I am writing a class similar to the following (but with a varying number of members, types of members, etc). Is it possible to do this automatically, easily, and for free?

So I would like to provide the parameters "Foo", "int", "apples", "bool", "banana", "Bar", and "clementine" and have the rest of code generated for me.

public class Foo
{
   public Foo(int apples, bool banana, Bar clementine)
   {
      m_Apples = apples;
      m_Banana = banana;
      m_Clementine = clementine;
   }

   public int Apples
   {
      get { return m_Apples; }
      set { m_Apples = value; }
   }

   public bool Banana
   {
      get { return m_Banana; }
      set { m_Banana = value; }
   }

   public Bar Clementine
   {
      get { return m_Clementine; }
      set { m_Clementine = value; }
   }

   private int m_Apples;
   private bool m_Banana;
   private Bar m_Clementine;
}
like image 706
Tim Gradwell Avatar asked Sep 26 '26 11:09

Tim Gradwell


1 Answers

Take a look at T4 Engine. It's included with VS2005 onwards.

like image 94
mmx Avatar answered Sep 28 '26 00:09

mmx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!