Avatar billede hyperactive Nybegynder
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???
Avatar billede arne_v Ekspert
17. april 2004 - 11:38 #1
Du mener generere properties med get og set ?
Avatar billede hyperactive Nybegynder
17. april 2004 - 12:05 #2
Yep

Hvis jeg f.eks. har

private int test;

ville det være fedt at slippe for at skrive

public int Test
{
  get
  {
      return test;
  }
  set
  {
      test = value;
  }
}
Avatar billede erve Nybegynder
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
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester