Please feel free to use my macro designed for the purpose.
You should declare property backer fields using an underbar character and a
lower-case first letter like so:
Private int _myInt;
Running the macro on this line creates a property such as:
public int MyInt
{
get{return _myInt;}
set{_myInt=valu e;}
}
For my own preference I have tied this macro to the Ctrl+Shft+V (for
variable) key combination.
You can define all your fields and then just hit your chosen hot-key
combination repeatedly to turn all fields into public properties with the
correct get-set code.
Full macro code is after my signature.
--
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.
-------------------------------------------------------
Sub FeildToProperty ()
DTE.ActiveDocum ent.Selection.S tartOfLine(vsSt artOfLineOption s.vsStartOfLine OptionsFirstCol umn)
DTE.ActiveDocum ent.Selection.E ndOfLine(True)
DTE.ActiveDocum ent.Selection.C opy()
DTE.ActiveDocum ent.Selection.E ndOfLine()
DTE.ActiveDocum ent.Selection.N ewLine()
DTE.ActiveDocum ent.Selection.S tartOfLine(vsSt artOfLineOption s.vsStartOfLine OptionsFirstCol umn)
DTE.ActiveDocum ent.Selection.P aste()
DTE.ActiveDocum ent.Selection.S tartOfLine(vsSt artOfLineOption s.vsStartOfLine OptionsFirstTex t)
DTE.ActiveDocum ent.Selection.W ordRight(True)
Dim currtext As String = DTE.ActiveDocum ent.Selection.T ext
If (currtext = "protected " Or currtext = "private " Or currtext = "public
") Then
DTE.ActiveDocum ent.Selection.D elete()
End If
DTE.ActiveDocum ent.Selection.E ndOfLine()
DTE.ActiveDocum ent.Selection.S tartOfLine(vsSt artOfLineOption s.vsStartOfLine OptionsFirstTex t)
DTE.ActiveDocum ent.Selection.T ext = "public "
DTE.ActiveDocum ent.Selection.W ordRight()
DTE.ActiveDocum ent.Selection.W ordRight(True)
DTE.ActiveDocum ent.Selection.C opy()
DTE.ActiveDocum ent.Selection.C harLeft()
DTE.ActiveDocum ent.Selection.D elete()
DTE.ActiveDocum ent.Selection.C harRight(True)
DTE.ActiveDocum ent.Selection.C hangeCase(vsCas eOptions.vsCase OptionsUppercas e)
DTE.ActiveDocum ent.Selection.W ordRight()
DTE.ActiveDocum ent.Selection.E ndOfLine(True)
DTE.ActiveDocum ent.Selection.D elete()
DTE.ActiveDocum ent.Selection.N ewLine()
DTE.ActiveDocum ent.Selection.T ext = "{"
DTE.ActiveDocum ent.Selection.N ewLine()
DTE.ActiveDocum ent.Selection.T ext = "}"
DTE.ActiveDocum ent.Selection.N ewLine()
DTE.ActiveDocum ent.Selection.L ineUp(False, 2)
DTE.ActiveDocum ent.Selection.E ndOfLine()
DTE.ActiveDocum ent.Selection.N ewLine()
DTE.ActiveDocum ent.Selection.T ext = "get{return "
DTE.ActiveDocum ent.Selection.P aste()
DTE.ActiveDocum ent.Selection.T ext = ";}"
DTE.ActiveDocum ent.Selection.N ewLine()
DTE.ActiveDocum ent.Selection.T ext = "set{"
DTE.ActiveDocum ent.Selection.P aste()
DTE.ActiveDocum ent.Selection.T ext = "=value;}"
DTE.ActiveDocum ent.Selection.L ineDown(False, 3)
DTE.ActiveDocum ent.Selection.S tartOfLine(vsSt artOfLineOption s.vsStartOfLine OptionsFirstTex t)
End Sub
-------------------------------------------------------
"Thorsten Ottosen" <th***@wmdata.c om> wrote in message
news:42******** *************** @news.sunsite.d k...
Dear all,
I'm new to C#, so forgive my stupid question.
In my question to avoid boilerplate code, I was wondering if
I could use attributes to generate some code for me.
For example
public class Foo
{
[GeneratePropert y("Field")]
int m_field;
}
should be equivalent to
public class Foo
{
int m_field;
public int Field
{
get { return m_field; }
set { m_field = value; }
}
}
Is that possible?
Thanks in advance
Thorsten