martin-brennan

articles / archive / about

Auto-Generate Property In VB.NET

At work back when I was using Visual Studio 2010, I had a macro for VB.NET that would generate properties in VB.NET from a list of private methods with a click of a button, because the VB.NET class property syntax is extremely tedious to write even for classes with a small number of properties. With Visual Studio 2012 macros have been removed so I had to find an alternative or otherwise suffer with copy/pasting or writing the whole thing out!

Luckily I came across an answer on StackOverflow that utilizes code snippets to generate a property in VB.NET including the private variable. You can see the answer here: VB.Net Keyboard Shortcut to auto-generate a Property on StackOverflow. All you need to do is write the word Property and hit tab twice, and it will generate something like this:

Private _PropName As String
Public Property PropName() As String
    Get
        Return _PropName
    End Get
    Set(ByVal value As String)
        _PropName = value
    End Set
End Property