Improve your C# code's clarity and adherence to coding standards by using Microsoft's recommended throw helpers for exception handling. This article demonstrates how to apply these helpers for common exceptions, like ArgumentNullException and ArgumentException, with real-world examples from the Entity Framework source code.
Category: Code Analysis
Microsoft .NET Code Analysis: Enhance Your Code Performance with Concrete Types
Discover the performance benefits of using concrete types over abstract or interface types in your code. Learn from a real-world Entity Framework example and gain practical insights into improving code quality and efficiency through this optimization technique.
Microsoft .NET Code Analysis: Optimizing String Methods for Performance – Leveraging Character Over String for Enhanced Efficiency
The article suggests using the string.Method(char) approach instead of string.Method(string) for strings containing a single character to improve performance. It highlights an example where this optimization can be applied in the Entity Framework source code and mentions that this deviation from the recommended guideline occurred 34 times in the codebase. The article also references violation codes CA1865 – CA1867 and mentions their severity settings in the .editorConfig file. Update March, 2024.
Microsoft .NET Code Analysis: Avoid Using Constant Arrays as Arguments
In this article, the author delves into the intricacies of the Entity Framework codebase, uncovering 168 instances that require optimization to boost performance. Explore the valuable insights and strategies for fine-tuning your Entity Framework application to ensure it operates at its peak efficiency.
Microsoft .NET Code Analysis: Properly Formatting Class Files
The article discusses the importance of consistent formatting in Microsoft .NET class files for improved code readability and collaboration among developers. It provides tips on how to set up formatting rules using Visual Studio's features and the EditorConfig file, covering various formatting options such as new lines, indentation, spacing, and wrap preferences. The article also highlights the use of CodeRush, a code refactoring tool, to enhance code formatting and organization.
Microsoft .NET Code Analysis: Random Is an Insecure Random Number Generator
The article discusses a security vulnerability in the use of the Random class for generating random numbers in .NET and recommends switching to the more secure RandomNumberGenerator for cryptographic and security-critical applications. The RandomNumberGenerator not only provides better security but also offers superior randomness and significant performance improvements in .NET 8. Updated September 2023.
Microsoft .NET Code Analysis: Simplify the New Expression for C#
The article discusses the introduction of a simplified new expression syntax in .NET 5, which allows for more concise and readable object initialization. The new syntax offers advantages such as reduced boilerplate code, improved readability, support for immutable types, and enhanced IDE integration.
Real World Coding Issues: Part 3 – Design, Diagnostics, and Other Common Code Issues
The article discusses real-world coding issues encountered in a contract project. Part 3 covers common coding issues related to design, diagnostics, and other areas, such as globalization, code duplication, and Linux-based development challenges. It emphasizes the importance of code quality, performance, and prioritizing code reviews to ensure a maintainable and efficient solution.
Microsoft .NET Code Analysis: Use Auto-Implemented Property
The article discusses the use of auto-implemented properties in Microsoft .NET code analysis. While the author generally advises against their excessive use, they highlight a real-world example where utilizing an auto-implemented property is advantageous due to its conciseness, readability, encapsulation, and ease of maintenance. The author recommends using tools like CodeRush from DevExpress to streamline the refactoring process.
Microsoft .NET Code Analysis: Validate Arguments of Public Methods
The author highlights the critical issue of insufficient argument validation in public methods, drawing on 20 years of experience. They emphasize its importance for maintaining encapsulation in object-oriented programming. A significant finding revealed 700 instances of this oversight, showcasing the necessity for proper validation to ensure data integrity. Recommended resources are mentioned for further learning.

You must be logged in to post a comment.