Generating getters & setters for private variables in VB.Net

I modified code submitted by Denis Briel. His submission was for C#.http://msd2d.com/Cont

ITPro Today

March 31, 2004

1 Min Read
ITPro Today logo

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

 

Read more about:

Microsoft
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like