471,319 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Get and set

Hi,

Is there a utility in C# or in visual web developer to automaticly create
get and set code lines for a given variable?

Thanks!
Dec 4 '05 #1
5 3684
Refactoring tools like CodeRush
(http://www.devexpress.com/Products/NET/CodeRush/) or ReSharper
(http://www.jetbrains.com/resharper/) will help you do that (among many
other things). If you're using VS2005, this functionality is already there
(http://msdn2.microsoft.com/en-us/library/xs0y516a.aspx).

Andrej

"Arjen" <bo*****@hotmail.com> wrote in message
news:dm**********@news3.zwoll1.ov.home.nl...
Hi,

Is there a utility in C# or in visual web developer to automaticly create
get and set code lines for a given variable?

Thanks!

Dec 4 '05 #2
Yes. In Visual Studio 2005, you can right-click on a field definition
and select Refactor > Encapsulate Field. This will convert the field to
a property, writing set and get accessors, and let you give the
property a different name while you're at it (updating the rest of your
code to refer to the new name).

Jesse

Dec 4 '05 #3
Where did they get all their great "new" features from? ;)

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Dec 4 '05 #4
Hi Arjen,

I wrote a small program to generate my basic class structure with gets
and sets etc. Let me know if you want the code and/or application.

Happy Coding,

Stefan
C# GURU
www.DotNETovation.com

"You always have to look beyond the horizon and can never be complacent
-- God forbid we become complacent."

Jozef Straus

*** Sent via Developersdex http://www.developersdex.com ***
Dec 5 '05 #5
You can use my macro...

It expects all feilds to start with an underscore and a lower-case letter
such as:

int _myInt;

It converts to a property removint the underscore and capitalizing the first
letter.

This is done because when I use a tool to convert from C# to VB.NET I don't
get problems with VB complaining in it's lame way about myInt and MyInt
being the same. (idiotic language!!!)
Sub FeildToProperty()

DTE.ActiveDocument.Selection.StartOfLine(vsStartOf LineOptions.vsStartOfLineOptionsFirstColumn)

DTE.ActiveDocument.Selection.EndOfLine(True)

DTE.ActiveDocument.Selection.Copy()

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.StartOfLine(vsStartOf LineOptions.vsStartOfLineOptionsFirstColumn)

DTE.ActiveDocument.Selection.Paste()

DTE.ActiveDocument.Selection.StartOfLine(vsStartOf LineOptions.vsStartOfLineOptionsFirstText)

DTE.ActiveDocument.Selection.WordRight(True)

Dim currtext As String = DTE.ActiveDocument.Selection.Text

If (currtext = "protected " Or currtext = "private " Or currtext = "public
") Then

DTE.ActiveDocument.Selection.Delete()

End If

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.StartOfLine(vsStartOf LineOptions.vsStartOfLineOptionsFirstText)

DTE.ActiveDocument.Selection.Text = "public "

DTE.ActiveDocument.Selection.WordRight()

DTE.ActiveDocument.Selection.WordRight(True)

DTE.ActiveDocument.Selection.Copy()

DTE.ActiveDocument.Selection.CharLeft()

DTE.ActiveDocument.Selection.Delete()

DTE.ActiveDocument.Selection.CharRight(True)

DTE.ActiveDocument.Selection.ChangeCase(vsCaseOpti ons.vsCaseOptionsUppercase)

DTE.ActiveDocument.Selection.WordRight()

DTE.ActiveDocument.Selection.EndOfLine(True)

DTE.ActiveDocument.Selection.Delete()

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.Text = "{"

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.Text = "}"

DTE.ActiveDocument.Selection.NewLine()

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

DTE.ActiveDocument.Selection.EndOfLine()

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.Text = "get{return "

DTE.ActiveDocument.Selection.Paste()

DTE.ActiveDocument.Selection.Text = ";}"

DTE.ActiveDocument.Selection.NewLine()

DTE.ActiveDocument.Selection.Text = "set{"

DTE.ActiveDocument.Selection.Paste()

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

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

DTE.ActiveDocument.Selection.StartOfLine(vsStartOf LineOptions.vsStartOfLineOptionsFirstText)

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

Ramuseco Limited .NET consulting
http://www.ramuseco.com

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.

"Arjen" <bo*****@hotmail.com> wrote in message
news:dm**********@news3.zwoll1.ov.home.nl...
Hi,

Is there a utility in C# or in visual web developer to automaticly create
get and set code lines for a given variable?

Thanks!

Dec 5 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.