Generating getters & setters for private variables in c#

You might have the problem to have multiple private variables you want to be able to access via get and set.

Normally you would have to write each getter and each setter manually. Since i was pretty tired of writing the same stuff over and over again, i wrote a little VB macro to generate getter and setter for all private variables in a file. Well, unfortunatly it only generates C#-Code yet. ;) But i will publish a multilanguage macro soon.

Simply goto "Tools" -> "Macros" -> "Macro Explorer"

In the tool window, expand "MyMacros" and right click on "Module1". Select "New Macro".

You should now have a new IDE open with the following defined:


Module Module1

Sub Macro1()

End Sub



Now replace the middle two lines with the the code from the attached file and add the imports as defined within the attached file.

Now you are all set! The last this to do to use the macro is to expand the "Module1" within the "Macro Explorer", right click the "WriteGetterAndSetter" and select run!

Like said before, it generates getter and setter for all private variables in the current file!

If some variables shouldn't be accessible from public, simply remove the corresponding property.

Hope someone might find this usefull ;)

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.