简体   繁体   English

Visual Studio自动打开折叠属性

[英]Visual Studio auto opening collapsed properties

Here is my problem. 这是我的问题。 I have a C# class file loaded in Visual Studio that I am working on. 我在Visual Studio中加载了一个C#类文件,我正在处理它。 I made a class and created some properties inside of said class. 我创建了一个类,并在所述类中创建了一些属性。 I collapsed the properties like so: 我崩溃了这些属性: 在此输入图像描述

I collapse the properties with the little + / - button on the side of each. 我用每个侧面的小+ / -按钮折叠属性。 I want to collapse each of them since I have a lot of other classes with properties and I don't want to see a lot of repetitive code (get, set). 我想折叠它们中的每一个,因为我有很多其他具有属性的类,我不想看到很多重复的代码(get,set)。

Closing them works fine but after I work on some other classes in the same file the properties re-open so I can see the code: 关闭它们工作正常,但在我处理同一文件中的其他类后,属性重新打开,所以我可以看到代码:

在此输入图像描述

This happens relatively often and is quite annoying. 这种情况经常发生并且非常烦人。 I have a lot of lines in the file and I sometimes have to work with a small screen. 我在文件中有很多行,有时我不得不使用小屏幕。 Is this a glitch/bug or something else? 这是一个小故障/错误或其他什么? (I am using Visual Studio 2010 C# Express) (我使用的是Visual Studio 2010 C#Express)

Thanks for your help. 谢谢你的帮助。

There is no way to solve this so far, but this does the trick. 到目前为止,没有办法解决这个问题,但这就是诀窍。 Press CTRL-M and then O and it will auto collapse everything in the current file you are on. CTRL-M然后按O ,它将自动折叠当前文件中的所有内容。

An alternate tip to @DJKRAZE's excellent answer is Resharper. 另一个提醒@ DJKRAZE的优秀答案是Resharper。 I use Resharper and it takes care of this automatically for me. 我使用Resharper,它会自动为我解决这个问题。 For example if I write this code: 例如,如果我写这个代码:

在此输入图像描述

The 4 line property procedure causes a Expand/Collapse that is causing you grief. 4行属性过程导致扩展/崩溃导致您悲伤。

Resharper makes it one line. Resharper使它成为一条线。 When I delete the last curly brace (namespace) and enter it again, the code is automatically formatted (Edit > Advanced > Format Document doesn't do this): 当我删除最后一个花括号(命名空间)并再次输入时,代码会自动格式化(编辑>高级>格式文档不执行此操作):

在此输入图像描述

You can use this: 你可以用这个:

#region some_name
//your variables or code whatever
#endregion

And then you can collapse the particular code, and the good thing it does not open like the way it happens in your case. 然后你可以折叠特定的代码,而不是像它在你的情况下那样打开的好东西。

See if that worked. 看看是否有效。

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

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