<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.dotnetzone.gr:443/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Παραμετροποίηση VS.NET IDE</title><link>https://www.dotnetzone.gr:443/cs/forums/34/ShowForum.aspx</link><description>Δημιουργία plug-ins και custom components, designers, etc.</description><dc:language>el</dc:language><generator>CommunityServer 2.1 SP3 (Build: 20423.1)</generator><item><title>Macro για τη μετατροπή variable σε property</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/1063.aspx</link><pubDate>Fri, 28 Jan 2005 20:32:28 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:1063</guid><dc:creator>cap</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/1063.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=34&amp;PostID=1063</wfw:commentRss><description>Αυτό το βρήκα σε μια έτοιμη mdb του CodeLib (&lt;a target="_blank" title="http://dotnet.4all.cc" href="http://dotnet.4all.cc"&gt;http://dotnet.4all.cc&lt;/a&gt;) που δίνεται μαζί με την εφαρμογή και είναι πρακτικότατο:&lt;br /&gt;&lt;br /&gt;&lt;font size="2"&gt; &lt;p&gt;Thanks to Visual Studio.NET macros, it is quite simple to automate the task of transforming a Public field into a Property with the same name that accesses a private field of the same type. &lt;/p&gt; &lt;p&gt;Press Alt-F11 (or invoke the Macro IDE from the Tools|Macros submenu, select one macro module in the left-most treeview, and double-click on it to bring up the corresponding code module. Now cut and paste the following procedure: &lt;/p&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;&lt;pre class="source"&gt;&lt;table border="0" cellspacing="0" width="100%"&gt;&lt;tr&gt;&lt;td width="15"&gt;&lt;/td&gt;&lt;td bgcolor="lightgrey" width="15"&gt;&lt;/td&gt;&lt;td bgcolor="lightgrey"&gt;&lt;br&gt;&lt;font face="Lucida Console, Courier" size="2"&gt;&lt;font face="Courier New" size="2"&gt; &lt;p&gt;Sub MorphVariableIntoProperty()&lt;/p&gt; &lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;&lt;p&gt;DTE.ActiveDocument.Selection.StartOfLine _&lt;/p&gt;&lt;p&gt;(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;&lt;p&gt;DTE.ActiveDocument.Selection.WordRight(True)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Delete()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Text = "Private m_"&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.EndOfLine(True)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Copy()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.EndOfLine()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.NewLine(2)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Text = "Public Property "&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Paste()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.NewLine()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.LineUp(False, 2)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.StartOfLine _&lt;/p&gt;&lt;p&gt;(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.WordRight(False, 2)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.WordRight(True)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Copy()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.LineDown(False, 2)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Indent(2)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Text = "Return m_"&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Paste()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.LineDown(False, 3)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Indent(2)&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Text = "m_"&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Paste()&lt;/p&gt;&lt;p&gt;DTE.ActiveDocument.Selection.Text = "= Value"&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;End Sub&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/pre&gt; &lt;p&gt;&lt;/font&gt;&lt;font size="2"&gt;Next, bring up the Tools-Options dialog box, go to Keyboard page, and assign a shortcut key combination to the Morph§VariableIntoProperty macro. Notice that the list of macros contains &lt;i&gt;complete&lt;/i&gt; macro names, that are prefixed by their module name. For example, you can assign the following key combination (two keystrokes): Ctrl-Shift-M, Ctrl-Shift-P. To reduce the odds of clashing with other macros, you can reduce the macro's visibility to the text editor. &lt;/p&gt; &lt;p&gt;Now you're ready. Let's say that you have the following variable declaration: &lt;/p&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;&lt;pre class="source"&gt;&lt;table border="0" cellspacing="0" width="100%"&gt;&lt;tr&gt;&lt;td width="15"&gt;&lt;/td&gt;&lt;td bgcolor="lightgrey" width="15"&gt;&lt;/td&gt;&lt;td bgcolor="lightgrey"&gt;&lt;br&gt;&lt;font face="Lucida Console, Courier" size="2"&gt;Dim Length As Single&lt;/font&gt;&lt;br&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/pre&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;p&gt;Position the caret anywhere on the DIM statement and press the shortcut assigned to the macro defined above. In a few instants Visual Studio renames the variable into m_Length, makes it private, and adds a Public property named Length: &lt;/p&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;&lt;pre class="source"&gt;&lt;table border="0" cellspacing="0" width="100%"&gt;&lt;tr&gt;&lt;td width="15"&gt;&lt;/td&gt;&lt;td bgcolor="lightgrey" width="15"&gt;&lt;/td&gt;&lt;td bgcolor="lightgrey"&gt;&lt;br&gt;&lt;font face="Lucida Console, Courier" size="2"&gt;&lt;font face="Courier New" size="2"&gt; &lt;p&gt;Private m_Length As Single &lt;/p&gt; &lt;p&gt;Public Property Length() As Single&lt;/p&gt; &lt;p&gt;Get&lt;/p&gt; &lt;p&gt;Return m_Length&lt;/p&gt; &lt;p&gt;End Get&lt;/p&gt; &lt;p&gt;Set(ByVal Value As Single)&lt;/p&gt; &lt;p&gt;m_Length = Value&lt;/p&gt; &lt;p&gt;End Set&lt;/p&gt; &lt;p&gt;End Property&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/pre&gt; &lt;p&gt;&lt;/font&gt;&lt;font size="2"&gt;Notice that this macro heavily relies on Visual Studio's ability to create a Property procedure template when you press the Enter key on a Property declaration. If this feature is disabled, the macro won't work. &lt;/p&gt;&lt;/font&gt;</description></item></channel></rss>