Skip to main content
 首页 » 编程设计

c#之在 Visual Studio 2015 中隐藏/折叠属性

2024年02月05日27lvdongjie

我们有一些代码使用带有长字符串参数(描述等)的属性 - 如果我们可以隐藏属性或至少它的参数,那就太好了。

是否可以在 Visual Studio 2015 中隐藏/折叠属性(在 C# 代码中)

请您参考如下方法:

  1. 您可以将参数声明为私有(private)常量:

    private const string LongTextParam = "Some very long text ..."; 
     
    ... 
     
    [MyAttribute(LongTextParam)] 
    public int SomeProperty { get; set; } 
    
  2. #region可以帮助你:

    #region MyAttribute 
    [MyAttribute("A very long string parameter .... ")] 
    #endregion 
    public int SomeProperty { get; set; } 
    

Visual Studio 中的编辑器可以折叠这些区域。

您也可以结合这两种方法 - 将参数文本移动到私有(private)字段/常量中并用区域包装它。