【问题标题】:Shortcut to generate field from property in Visual studio在 Visual Studio 中从属性生成字段的快捷方式
【发布时间】:2014-07-31 07:34:09
【问题描述】:

VS中是否有任何快捷方式可以从对应属性定义字段?

【问题讨论】:

    标签: visual-studio-2012 shortcut


    【解决方案1】:

    如果您要为自动生成的属性生成后备存储:

     public string MyProperty { get; set; }
    

    收件人:

     public string _myProperty;
     public string MyProperty { 
          get { return _myProperty; } 
          set { _myProperty = value; } 
     }
    

    那么在 Visual Studio 中没有捷径可以做到这一点Resharper and CodeRush 等重构工具提供此功能。

    在 Visual Studio 中,"Encapsulate field" 重构与 ctrl+r,e 相反。

     public string _myProperty;
    

    收件人:

     public string _myProperty;
     public string MyProperty { 
          get { return _myProperty; } 
          set { _myProperty = value; } 
     }
    

    【讨论】:

    • Resharper 和 CodeRush 等重构工具提供了“创建后备存储”这一功能 --- 我在 resharper 中哪里可以找到该选项?
    • Resharper 中总是有东西;)。在 alt-enter 下。
    猜你喜欢
    • 2011-04-21
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 2012-11-26
    • 2010-09-06
    • 2021-08-31
    • 2018-01-25
    • 2021-12-15
    相关资源
    最近更新 更多