问题
When working on C#, I often do this:
#region Properties
public int Property1{get;set;}
...(more properties)
#endregion
This makes Visual Studio add the option to fold the code inside the region. Offcourse, you can use regions for anything, it's not limited to Properties or anything at all.
I'm wondering 2 things:
- Is this just something to make Visual Studio add code folding to an area of the editor or does it affect the compiler?
- Can I do something similar in Netbeans?
回答1:
- (In Netbeans at least) It is purely a programmer aid and has no effect on compilation
- Yes you can
One caveat to the folding reference:
Please note that the above examples are for java language. In other languages custom folds may not be supported or you may have to use different characters for marking line comments.
回答2:
- It does not affect compilation, it's just to organise code in the editor. You can pick up on arguments on when best to use them in this question.
In NetBeans you can use Custom Folds, depending on the language:
// <editor-fold defaultstate="collapsed" desc="My Fold">
Your amazing code
// </editor-fold>
The attributes are optional. Without defaultstate
specified the region will default to expand (except for when you first wrap code in it!)
回答3:
The latest Netbeans 8.1 has already this feature build in, You need just select you rows and then click on the "light bulb" icon, then select:
enter code hereSurround with // <editor-fold defaultstatus="collapsed" desc="comment">...
This is the source: http://wiki.netbeans.org/SurroundWithCodeFolding
回答4:
I wrote a Macro for folding by mouse draging.
My shortcute: CTRL+SHIFT+Q
Folding Macro:
cut-to-clipboard
"// <editor-fold desc=\"This is my custom folding\" defaultstate=\"collapsed\">"
paste-from-clipboard
"// </editor-fold>"
UNFolding Macro Shortcut: ctrl+SUBTRACK
来源:https://stackoverflow.com/questions/1251803/can-you-set-some-sort-of-custom-code-folding-in-netbeans-like-in-visual-studio