繁体   English   中英

Visual Studio 2008类图创建空属性,而不是autoproperties

[英]Visual Studio 2008 class diagram creates empty properties, not autoproperties

我在Visual Studio 2008中使用类图来创建一些具有属性的类。 我注意到,当我在类图中创建一个新属性时,它出现在这样的代码中:

public DateTime DateBilled
{
    get
    {
        throw new System.NotImplementedException();
    }
    set
    {
    }
}

呸。 我更倾向于它最终成为这样的autoproperty:

public DateTime DateBilled { get; set; }

有什么方法可以改变或定制吗?

这不是您正在寻找的,但它可能会让您接近您需要的结果。

这是一个Visual Studio 2008宏,它将找到生成的类图获取属性并将其替换为自动属性。

  1. 在VS中,转到视图 - >其他Windows - >宏资源管理器
  2. 右键单击“MyMacros”并选择“New module ...”
  3. 给它任何你想要的名字
  4. 右键单击它并选择“新宏”
  5. 粘贴此代码

这是代码:

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

这几乎只是一个黑客,我不确定它是否适用于类设计器的所有输出,但它在我的测试中工作到目前为止,它肯定节省了一些按键。

希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM