This repository is dedicated to common performance and code quality analyzers to follow the best practices surrounding the use of data structures and their APIs located under System.Collections & System.Linq.
This project was developed as an internal hackathon project as a proof of concept and depicts the idea. It’s still a prototype and using it could give you false positives. Moreover, the ruleset in the library hasn't been finalized and is subject to change. We're still working on these ideas to make sure they are accurate and reflect the best development practices in .NET. We welcome and encourage contributions on those ideas. For those interested in helping us that way, please read the contribution guidelines for the project.
Nonetheless, it could provide useful insights to the developers. You can either consult the project’s roadmap or subscribe to the project’s notifications to know when the project will move outside of its prototype phase.
The core mission of the .NET Compiler Platform ("Roslyn") is opening up the C# and Visual Basic compilers and allowing tools and developers to share in the rich information compilers have about programs. Code analysis tools improve code quality, and code generators aid in application construction. As tools get smarter, they need access to more and more of the deep code knowledge that only compilers possess.
An analyzer library for C#
and VB.NET
empowered by Roslyn to help .NET developers to harness the full capabilities and performance of the CLR. The set of analyzers will analyze your code for quality, performance and maintainability.
There are many code analysis libraries for .NET, but they do not focus on how we should use data structures such as an List<T>
. Using a framework like .NET makes it easier for software developers to create an impact on their business and solve problems for their customers. The problem is that even though you can use a list everywhere just because you're used to its APIs doesn't mean you should. Each data structure is built to serve a different purpose and knowing when to use each one within an algorithm could make a considerable difference in performance in the hot paths.
The purpose of this library is to empower the software developers using .NET and enable them to leverage the best practices which sometimes could make a difference from quality or performance point of view. The goal is to pinpoint the issues concerning the usage of types found in System.Collections such as IEnumerable<T>
or extension methods found in System.Linq. This tool is here to help developers make better performance decisions through a set of micro-optimizations.
-
Suggesting, for instance, using an
HashSet<T>
whenever a developer is doing a heavy Contains check on theirList<T>
. -
Suggesting using a for-loop when iterating on a collection that allows random access such as
IList<T>
. -
Suggesting using a separate method to yield values lazily instead of taking the time to create a temporary list.
See the ruleset file for details.
Requirements to use:
- Recommended version of Visual Studio: Visual Studio 2015
- Minimal NET Framework supported: 4.6+
- Minimal .NET Core : 1.0
You can download the NuGet Package from here
Requirements to build the solution:
- Recommended version of Visual Studio: Visual Studio 2017 version 15.3
- Minimal NET Framework supported: 4.6+
- Minimal .NET Core : 1.0
Installing the package from the Package Manager: Install-Package DotNet.SystemCollections.Analyzers
Each project in Visual Studio has a "treat warnings as errors" option. If you wish to treat the warnings given by the analyzers as errors:
-
Right-click on your project, select "Properties".
-
Click "Build".
-
Update your warning settings in Visual Studio by either
-
Switching "Treat warnings as errors" from "Specific warnings" or "None" to "All"
-
Add specific warnings from the library as errors.
-
Please note that we have a code of conduct. Please follow it in all your interactions with this project.
See the contributing file for more details.
See the release-notes file for details.
Version 1.0 - Finalization of the ruleset covered by the library
Version 2.0 - Automatic code suggestions for best practices
This project is licensed under the MIT License - see the license file for details
Hypertherm's Robotic Software team develops Robotmaster, the world’s leading CAD/CAM robot programming software, used by some of the largest multinationals such as Boeing and Mercedes and the smallest industrial manufacturing shops performing short customized runs. To know more about Robotmaster, please visit our website.