Can VS.net generate properties

  • Thread starter Thread starter jw56578
  • Start date Start date
J

jw56578

is there a way to automatically generate properties from fields in
vs.net
 
is there a way to automatically generate properties from fields in
vs.net

There is no built-in way to do that, but you can write your own add-in/macro
to create the property or use 3rd-party add-ins which support that.
 
No, but if you use a simple recorded macro you can save the macro for later
use. I just recorded this one directly from the keyboard using the
Ctrl+Shift+R hot-key combination. As you can see, it grabs the field name,
modifies it, pastes in extra bits and creates a property. It uses my
standard of naming fields with an underbar and an initial lower-case letter
so that for example a field named "_foo" creates a property named "Foo"

Sub VBFieldToProperty()

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)

DTE.ActiveDocument.Selection.WordRight()

DTE.ActiveDocument.Selection.WordRight(True)

DTE.ActiveDocument.Selection.Copy()

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.Text = "public property "

DTE.ActiveDocument.Selection.Paste()

DTE.ActiveDocument.Selection.WordLeft()

DTE.ActiveDocument.Selection.Delete()

DTE.ActiveDocument.Selection.CharRight(True)

DTE.ActiveDocument.Selection.ChangeCase(vsCaseOptions.vsCaseOptionsUppercase)

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.LineUp()

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.WordLeft(True, 2)

DTE.ActiveDocument.Selection.Copy()

DTE.ActiveDocument.Selection.LineDown()

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.Paste()

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.Text = "return "

DTE.ActiveDocument.Selection.LineUp(False, 3)

DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)

DTE.ActiveDocument.Selection.WordRight()

DTE.ActiveDocument.Selection.WordRight(True)

DTE.ActiveDocument.Selection.Copy()

DTE.ActiveDocument.Selection.LineDown(False, 3)

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.Paste()

DTE.ActiveDocument.Selection.LineDown(False, 3)

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.Indent(2)

DTE.ActiveDocument.Selection.Paste()

DTE.ActiveDocument.Selection.Text = "=value"

DTE.ActiveDocument.Selection.LineDown()

DTE.ActiveDocument.Selection.LineUp()

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.LineDown()

DTE.ActiveDocument.Selection.LineUp(False, 3)

End Sub


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top