Generating getters & setters for private variables in VB.Net

I modified code submitted by Denis Briel. His submission was for C#.

http://msd2d.com/Content/Tip_viewitem_03.aspx?section=dotNet&id=c11c7e0d-0ee2-4faf-9f4f-9267179ec8b2

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 VB.Net.

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:

Public Module Module1

Sub Macro1()

End Sub

End Module

Now replace all code with the the code from 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_VB" 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

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.
Publish