Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 22, 2025

Summary

This PR consolidates C# code snippets from 17 of @kurnakovv's open pull requests into the existing all-rules project, creating a single compilable code base for all the code analysis rule examples.

Problem

Multiple open PRs from @kurnakovv are adding C# code examples for various CA (Code Analysis) rules. These snippets were scattered across different PRs and needed to be consolidated into a single project to ensure they:

  • Compile correctly together
  • Follow consistent patterns
  • Are easier to maintain
  • Can be tested as a unified codebase

Solution

Added 17 new C# snippet files to the existing all-rules.csproj project at docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/:

Files Added

File Rule Description
ca1720.cs CA1720 Identifiers should not contain type names
ca1725.cs CA1725 Parameter names should match base declaration
ca1727.cs CA1727 Use PascalCase for named placeholders
ca1822.cs CA1822 Mark members as static
ca1823.cs CA1823 Avoid unused private fields
ca1844.cs CA1844 Provide memory-based overrides of async methods
ca2008.cs CA2008 Do not create tasks without passing a TaskScheduler
ca2012.cs CA2012 Use ValueTasks correctly
ca2014.cs CA2014 Do not use stackalloc in loops
ca2201.cs CA2201 Do not raise reserved exception types
ca2207.cs CA2207 Initialize value type static fields inline
ca2219.cs CA2219 Do not raise exceptions in exception clauses
ca2224.cs CA2224 Override Equals on overloading operator equals
ca2226.cs CA2226 Operators should have symmetrical overloads
ca2253.cs CA2253 Named placeholders should not be numeric values
ca2256.cs CA2256 All members must have implementation in DynamicInterfaceCastable
ca2257.cs CA2257 Members should be static in DynamicInterfaceCastable interfaces

Implementation Details

  • Target Framework: .NET 9.0
  • Build Status: ✅ Successful (0 errors, 24 expected warnings)
  • Dependencies: Uses existing project dependencies (Microsoft.Extensions.Logging, System.Data.SqlClient, etc.)

Special Handling

Some snippets (ca2224, ca2226) demonstrate code that intentionally violates rules in ways that would prevent compilation. These were handled by:

  • Commenting out the violating code sections with /* */ comments
  • Keeping the correct/good examples uncommented and compilable
  • Using #pragma warning directives to suppress expected analyzer warnings

This approach allows the documentation to show both incorrect and correct code while maintaining a compilable project.

Testing

  • Built project successfully with dotnet build
  • Verified all 94 C# files in the project compile without errors
  • Confirmed expected code analysis warnings are present (demonstrating the rules work correctly)

Related PRs

This consolidates code snippets from the following open PRs by @kurnakovv:
#48959, #48961, #48963, #48965, #48967, #49034, #49036, #49038, #49040, #49059, #49061, #49063, #49065, #49087, #49090, #49107, #49110

Note: PRs #49042, #49088, and #49092 were reviewed but contain only fixes to existing code or inline markdown examples, not new snippet files.

Original prompt

Please take all the C# code snippets that are added in these pull requests (https://github.com/dotnet/docs/issues?q=is%3Aissue%20state%3Aopen%20author%3Akurnakovv) and put them into a single project.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Consolidate C# code snippets from multiple pull requests Consolidate C# code snippets from kurnakovv's PRs into single compilable project Oct 22, 2025
@Copilot Copilot AI requested a review from gewarren October 22, 2025 20:15
Copilot finished work on behalf of gewarren October 22, 2025 20:15
@gewarren gewarren closed this Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants