C# Code Review Standards Document
Introduction
This document outlines the standard parameters and best practices used in daily C# code reviews. It ensures consistency, readability, maintainability, and performance across projects.
1. Naming Conventions
Classes & Interfaces: Use PascalCase (e.g.,
CustomerService,IRepository).Methods: Use PascalCase (e.g.,
GetCustomerById).Variables & Fields: Use camelCase (e.g.,
customerName).Constants: Use ALL_CAPS with underscores (e.g.,
MAX_RETRY_COUNT).Async Methods: End with
Async(e.g.,SaveDataAsync).
2. Code Structure
Keep methods short and focused (ideally < 30 lines).
Follow Single Responsibility Principle (SRP).
Use regions sparingly for logical grouping.
Ensure proper indentation and spacing.
3. Error Handling
Use
try-catch-finallyblocks appropriately.Avoid swallowing exceptions; always log them.
Use custom exceptions for domain-specific errors.
Prefer
throw;overthrow ex;to preserve stack trace.
4. Logging & Monitoring
Use structured logging (e.g., Serilog, NLog).
Avoid logging sensitive information.
Ensure logs provide context (user ID, request ID).
5. Performance & Optimization
Use
async/awaitfor I/O-bound operations.Avoid unnecessary object creation.
Use
StringBuilderfor string concatenation in loops.Optimize LINQ queries; avoid client-side evaluation.
Use caching where applicable.
6. Security
Validate all user inputs.
Use parameterized queries to prevent SQL injection.
Avoid storing sensitive data in plain text.
Follow OWASP guidelines for secure coding.
7. Testing
Ensure unit tests cover critical logic.
Use mocking frameworks for dependencies.
Follow AAA (Arrange-Act-Assert) pattern in tests.
Maintain >80% code coverage.
8. Documentation
Use XML comments for public methods.
Provide clear summaries for classes and interfaces.
Keep README and API documentation updated.
9. Code Review Checklist
✅ Naming conventions followed
✅ Code is readable and maintainable
✅ No hard-coded values
✅ Proper error handling
✅ Logging implemented
✅ Performance optimized
✅ Security best practices applied
✅ Unit tests written and passing
✅ Documentation updated
Conclusion
By following these standards, teams can ensure high-quality, maintainable, and secure C# code. Regular reviews based on these parameters help catch issues early and promote best practices.
This was part of Interview Preparation With Bipin — Let’s Crack It!
Comments
Post a Comment