|
2 | 2 | title: Options, Text Editor, C#, Advanced
|
3 | 3 | description: Learn how to use the Advanced page in the C# section to modify the settings for editor formatting, code refactoring, and XML documentation comments for C#.
|
4 | 4 | ms.custom: SEO-VS-2020
|
5 |
| -ms.date: 06/01/2021 |
| 5 | +ms.date: 10/29/2022 |
6 | 6 | ms.topic: reference
|
7 | 7 | f1_keywords:
|
8 | 8 | - VS.ToolsOptionsPages.Text_Editor.CSharp.Outlining
|
@@ -149,6 +149,76 @@ Select these check boxes to display dotted vertical lines between the curly brac
|
149 | 149 |
|
150 | 150 | When selected, inserts the XML elements for XML documentation comments after you type the `///` comment introduction. For more information about XML documentation, see [XML Documentation Comments (C# Programming Guide)](/dotnet/csharp/programming-guide/xmldoc/).
|
151 | 151 |
|
| 152 | +## Extract Method |
| 153 | + |
| 154 | +- Don't put ref or out on custom struct |
| 155 | + |
| 156 | + Uncheck this checkbox to avoid potentionally unintended cloning of structs by refencing existing struct objects when extracting an expression into a method call. |
| 157 | + |
| 158 | + ### Example |
| 159 | + |
| 160 | + Supposed the following `class` and `struct` exist in your code: |
| 161 | + |
| 162 | + ```csharp |
| 163 | + public struct CustomStruct |
| 164 | + { |
| 165 | + private int Count; |
| 166 | + |
| 167 | + public int Bump => ++Count; |
| 168 | + } |
| 169 | + |
| 170 | + |
| 171 | + public class CustomClass |
| 172 | + { |
| 173 | + public void DoIt() |
| 174 | + { |
| 175 | + CustomStruct cs = new CustomStruct(); |
| 176 | + int i = 0; |
| 177 | + |
| 178 | + i += cs.Bump; // select this line |
| 179 | + } |
| 180 | + } |
| 181 | + ``` |
| 182 | + |
| 183 | + If the "Don't put ref or out on custom struct" option is **unchecked**, then the "Extract method" feature generates the following: |
| 184 | + |
| 185 | + ```C# |
| 186 | + public class CustomClass |
| 187 | + { |
| 188 | + public void DoIt() |
| 189 | + { |
| 190 | + CustomStruct cs = new CustomStruct(); |
| 191 | + int i = 0; |
| 192 | + |
| 193 | + NewMethod(ref cs, ref i); |
| 194 | + } |
| 195 | + |
| 196 | + private static void NewMethod(ref CustomStruct cs, ref int i) |
| 197 | + => i += cs.Bump; |
| 198 | + } |
| 199 | + ``` |
| 200 | + |
| 201 | + If the "Don't put ref or out on custom struct" option is **checked**, then the "Extract method" feature generates the following: |
| 202 | + |
| 203 | + ```C# |
| 204 | + public class CustomClass |
| 205 | + { |
| 206 | + public void DoIt() |
| 207 | + { |
| 208 | + CustomStruct cs = new CustomStruct(); |
| 209 | + int i = 0; |
| 210 | + |
| 211 | + i = NewMethod(cs, i); |
| 212 | + } |
| 213 | + |
| 214 | + private static int NewMethod(CustomStruct cs, int i) |
| 215 | + { |
| 216 | + i += cs.Bump; |
| 217 | + return i; |
| 218 | + } |
| 219 | + } |
| 220 | + ``` |
| 221 | + |
152 | 222 | ## Inline Hints
|
153 | 223 |
|
154 | 224 | - Inline Parameter Name Hints
|
|
0 commit comments