17. april 2004 - 11:16
Der er
2 kommentarer og 1 løsning
Automatisk generering af get/set metoder
Findes der en funktion eller en add in, som kan generere standard get/set metoder i Visual Studio udfra de definerede private fields???
Annonceindlæg fra 7N A/S
17. april 2004 - 12:58
#3
Det gør der ikke standard, men det er meget let at indspille en makro, gemme den, og dernæst tiknytte den et alias i commandvinduet.F.eks nedenstående: - I editvinduet skriver du f.eks: int Antal - Stil til i commandvinduet og tilknyt macroen til f.eks alias'et mp: - "alias mp Macros.MyMacros.RecordingModule.MakeProperty" skriv mp og propertyen bliver genereret Sub MakeProperty() DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) DTE.ActiveDocument.Selection.WordRight(True, 2) DTE.ActiveDocument.Selection.Copy() DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) DTE.ActiveDocument.Selection.Text = "private " DTE.ActiveDocument.Selection.WordRight() DTE.ActiveDocument.Selection.Text = "_" DTE.ActiveDocument.Selection.CharRight(True) DTE.ActiveDocument.Selection.ChangeCase(vsCaseOptions.vsCaseOptionsLowercase) DTE.ActiveDocument.Selection.EndOfLine() DTE.ActiveDocument.Selection.Text = ";" 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 = "}" DTE.ActiveDocument.Selection.LineUp() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "get { return " DTE.ActiveDocument.Selection.Paste() DTE.ActiveDocument.Selection.WordLeft() DTE.ActiveDocument.Selection.Text = "_" DTE.ActiveDocument.Selection.CharRight(True) DTE.ActiveDocument.Selection.ChangeCase(vsCaseOptions.vsCaseOptionsLowercase) DTE.ActiveDocument.Selection.WordLeft() DTE.ActiveDocument.Selection.WordLeft(True) DTE.ActiveDocument.Selection.Delete() DTE.ActiveDocument.Selection.WordRight(True) DTE.ActiveDocument.Selection.Copy() DTE.ActiveDocument.Selection.EndOfLine() 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.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) DTE.ActiveDocument.Selection.LineUp(False, 3) DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) DTE.ExecuteCommand("Window.ActivateDocumentWindow") End Sub