简体   繁体   中英

Hide/Collapse Attributes in Visual Studio 2015

We have some code which uses attributes with long string Parameters (descriptions and the like) - it would be great, if we could hide attributes or at least its Parameters.

Is it possible to hide/collapse attributes (in C# code) in Visual Studio 2015

  1. You can declare your parameter as a private constant:

     private const string LongTextParam = "Some very long text ..."; ... [MyAttribute(LongTextParam)] public int SomeProperty { get; set; } 
  2. #region can help you:

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

Editor in Visual Studio can collapse such regions.

Also you can combine both approaches - move param text into private field / constant and wrap it with region.

I think it's not possible, but you can use regions

    #region SomeShortDescription
    [MyAttribute("Long description here...")]
    #endregion

For more information: https://msdn.microsoft.com/en-us/library/9a1ybwek.aspx

As other have pointed out, this can't be done currently on VS.

The suggested solution of using regions will probably work although I would advise against it.

I can see how attributes can be obstrusive if you have many, or just a few but they have many, or long, parameters, but they might be an essential part of your code and without seeing it you might miss something fundamental.

My 2 cents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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