I'm using a Class Diagram in Visual Studio 2008 to create some classes with properties. I notice that when I create a new property in the Class Diagram, it comes out in code like this:
public DateTime DateBilled
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}
Yuck. I'd much rather it end up as an autoproperty like this:
public DateTime DateBilled { get; set; }
Is there some way I can change or customize that?
This isn't exactly what you're looking for, but it might get you close to the result you need.
This is a Visual Studio 2008 Macro which will find the class diagram generated get properties and replace them with auto properties.
Here's the code:
DTE.ExecuteCommand("Edit.Find")
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
DTE.Find.FindWhat = "<get$"
DTE.Find.MatchCase = False
DTE.Find.MatchWholeWord = False
DTE.Find.Backwards = False
DTE.Find.MatchInHiddenText = True
DTE.Find.Action = vsFindAction.vsFindActionFind
While DTE.Find.Execute() <> vsFindResult.vsFindResultNotFound
DTE.ActiveDocument.Selection.LineDown(True, 6)
DTE.ExecuteCommand("Edit.Delete")
DTE.ActiveDocument.Selection.Text = "get; set;"
End While
This is pretty much just a hack, and I'm not sure if it will work with all the output from the class designer, but it has worked in my testing so far and it certainly saves a few keystrokes.
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With