-
Notifications
You must be signed in to change notification settings - Fork 6k
Modernize code examples for CA rules #48745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. I had a few optional suggestions and then, let's
docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1045.cs
Outdated
Show resolved
Hide resolved
docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1806.cs
Outdated
Show resolved
Hide resolved
docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1806.cs
Show resolved
Hide resolved
docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2227.cs
Outdated
Show resolved
Hide resolved
docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2235.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modernizes code examples for CA (Code Analysis) rules by updating them to use contemporary C# and VB.NET syntax and patterns. The changes improve readability and demonstrate current best practices while maintaining the same educational purpose.
- Replaces older syntax with modern equivalents (collection expressions, target-typed new expressions, primary constructors)
- Updates data access examples from SQL Server to OLE DB with appropriate platform attributes
- Removes unnecessary code and simplifies class implementations using modern language features
Reviewed Changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
CA2235 snippet files | Modernized serialization example with primary constructor and auto-properties |
CA2100 snippet files | Updated SQL examples to use OLE DB with platform-specific attributes |
CA1816 snippet files | Replaced SQL connection examples with MemoryStream for simpler disposal pattern |
CA1806 snippet files | Modernized method result handling examples with null-conditional operators |
CA1045 snippet files | Extensively modernized ref/out parameter examples with records and switch expressions |
Various CA rule snippets | Applied target-typed new expressions, collection expressions, and simplified syntax |
Documentation files | Updated example structure and minor text improvements |
.editorconfig files | Added CA2100 severity configuration |
Related to #48007.
Requires #48743 to be merged first (for project files).Internal previews