Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / August 2003

Tip: Looking for answers? Try searching our database.

Generating properties from members

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Kozlowski - 24 Jul 2003 15:05 GMT
Developing in C# with VS.NET 2002, I want to create properties to
expose a bunch of the private members in a class.  I'm sure VS.NET has
to have a way to do this automatically, as it's the sort of tedious
and mechanical task that code generation was made for, but I sure
can't figure out how to do it.

Can anyone point me at what I'm missing?

Signature

Mike Kozlowski
http://www.klio.org/mlk/

Todd C. Gleason - 12 Aug 2003 17:41 GMT
I use the following macro in VS.NET 2003 (probably works
in 2002 as well).  Just go to the Macro Explorer and go
into the editor, and paste this in:

   Sub CSAddProperty()
       DTE.ActiveDocument.Selection.EndOfLine()
       DTE.ActiveDocument.Selection.StartOfLine
(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
       DTE.ActiveDocument.Selection.WordRight()
       DTE.ActiveDocument.Selection.EndOfLine(True)
       DTE.ActiveDocument.Selection.WordLeft(True)
       DTE.ActiveDocument.Selection.Copy()
       DTE.ActiveDocument.Selection.EndOfLine()
       DTE.ActiveDocument.Selection.NewLine()
       DTE.ActiveDocument.Selection.Text = "public "
       DTE.ActiveDocument.Selection.Paste()
       DTE.ActiveDocument.Selection.NewLine()
       DTE.ActiveDocument.Selection.Text = "{"
       DTE.ActiveDocument.Selection.NewLine()
       DTE.ActiveDocument.Selection.Text = "get {  
return "
       DTE.ActiveDocument.Selection.Paste()
       DTE.ActiveDocument.Selection.Text = ";  } }"
       DTE.ActiveDocument.Selection.EndOfLine()
       DTE.ActiveDocument.Selection.LineUp()
       DTE.ActiveDocument.Selection.EndOfLine()
       DTE.ActiveDocument.Selection.NewLine()
       DTE.ActiveDocument.Selection.Text = "set {  "
       DTE.ActiveDocument.Selection.Paste()
       DTE.ActiveDocument.Selection.Text = " = vale"
       DTE.ActiveDocument.Selection.DeleteLeft()
       DTE.ActiveDocument.Selection.Text = "ue;  }"
       DTE.ActiveDocument.Selection.LineUp()
       DTE.ActiveDocument.Selection.StartOfLine
(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
       DTE.ActiveDocument.Selection.EndOfLine()
       DTE.ActiveDocument.Selection.WordLeft(False, 3)
       DTE.ActiveDocument.Selection.StartOfLine
(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)
       DTE.ActiveDocument.Selection.WordRight(True, 3)
       DTE.ActiveDocument.Selection.DeleteLeft()
       DTE.ActiveDocument.Selection.StartOfLine
(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
       DTE.ActiveDocument.Selection.LineDown()
       DTE.ActiveDocument.Selection.StartOfLine
(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
       DTE.ActiveDocument.Selection.EndOfLine()
       DTE.ActiveDocument.Selection.WordLeft(False, 5)
       DTE.ActiveDocument.Selection.StartOfLine
(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)
       DTE.ActiveDocument.Selection.WordRight(True, 2)
       DTE.ActiveDocument.Selection.DeleteLeft()
       DTE.ActiveDocument.Selection.LineDown(False, 2)
       DTE.ActiveDocument.Selection.EndOfLine()
       DTE.ActiveDocument.Selection.StartOfLine
(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
   End Sub

This isn't a very smart macro, I'll warn you, but for
simple data types it usually does most of the busywork
for me.  I put the cursor over a data definition and then
invoke it.  I still have to modify the property name but
it works all right.

If any one requests, I also have macros to:
- add properties in C++
- blindly add code comments in C++ (not intelligently at
all)
- Wrap the current line with the "undef new" style
pragmas.
- add a region in C#
- make a region for a property in C#

--Todd C. Gleason

>-----Original Message-----
>Developing in C# with VS.NET 2002, I want to create properties to
[quoted text clipped - 4 lines]
>
>Can anyone point me at what I'm missing?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.