提供选项禁用预处理行删除缩进#8
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an option to disable automatic indent removal for preprocessor directives in C# code generation. The default behavior has been changed from always processing preprocessor lines to requiring explicit opt-in via the new RemoveIndentForPreprocessorLines property. The preprocessor detection logic has also been enhanced to avoid false positives by checking that characters following # are valid preprocessor indicators (letters, !, or :), which handles edge cases like shebang lines and special directives.
Key changes:
- Added
RemoveIndentForPreprocessorLinesproperty (defaults tofalse) to control preprocessor line processing - Enhanced preprocessor detection to validate characters after
#symbol - Updated line processor assignment to be conditional based on the new property
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| SourceTextBuilder.cs | Adds RemoveIndentForPreprocessorLines property with XML documentation and updates ToString() to conditionally apply the CSharp line processor |
| IndentedStringBuilder.cs | Enhances ProcessCSharpCodeLine method with improved preprocessor detection logic and whitespace-only line handling |
Comments suppressed due to low confidence (1)
src/dotnetCampus.CodeAnalysisUtils/Generators/Builders/IndentedStringBuilder.cs:439
- 此行文本与上方列表项(第437行)中的描述重复。建议删除第439行,仅保留列表中的描述即可。
/// 识别预处理指令行(以 # 开头的行),并确保这些行不进行缩进。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
现在,默认不会处理预编译行了