Re: C# 3.0 partial methods and automatic properties

Stoyan Damov <[email protected]> Sat, 11 Nov 2006 00:17:18 +0200
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <[email protected]>
> The issue you bring up is a VERY valid one... you get the ability to
> change the method from the trivial stub to an actual method that does
> something for free (from recompile of clients). This allows you to
> standardize on the pattern of always having property accessors in a
> wrist-friendly way.

Wow, what a terrific feature! You can record a macro[1] (ctrl-shift-r)
that does that in a few seconds. Below is a macro that when played
(ctrl-shift-p) on:

string property[ctrl-shift-p]

will replace it with

private string property_;
public string Property
{
    get
    {
        return property_;
    }
    set
    {
        property_ = value;
    }
}

[1]
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module RecordingModule


    Sub TemporaryMacro()
        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText,
True)
        DTE.ActiveDocument.Selection.Copy()
        DTE.ActiveDocument.Selection.EndOfLine()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.EndOfLine()
        DTE.ActiveDocument.Selection.WordLeft(True)
        DTE.ActiveDocument.Selection.Copy()
        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
        DTE.ActiveDocument.Selection.Text = "private "
        DTE.ActiveDocument.Selection.EndOfLine()
        DTE.ActiveDocument.Selection.Text = "_;"
        DTE.ActiveDocument.Selection.LineDown()
        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
        DTE.ActiveDocument.Selection.Text = "public "
        DTE.ActiveDocument.Selection.EndOfLine()
        DTE.ActiveDocument.Selection.WordLeft()
        DTE.ActiveDocument.Selection.CharRight(True)
        DTE.ActiveDocument.Selection.ChangeCase(VsCaseOptions.VsCaseOptionsUppercase)
        DTE.ActiveDocument.Selection.EndOfLine()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "{"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "}"
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Indent()
        DTE.ActiveDocument.Selection.Text = "get"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "{"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "}"
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Indent()
        DTE.ActiveDocument.Selection.Text = "return "
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.Text = "_;"
        DTE.ActiveDocument.Selection.LineDown()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "set"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "{"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "}"
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Indent()
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.Text = "_ = value;"
    End Sub
End Module

Cheers,
Stoyan

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com