Creating a Roslyn Analyzer
People create custom Roslyn Analyzers when they experience common issues in their code that no existing analyzer addresses. These custom analyzers help enforce rules that specific organizations or teams find to be useful. However, these organization-specific rules tend to be less relevant to the larger .NET community.
Here are a few examples of when you might want to build a custom analyzer:
- Your team has been having issues with too many
FormatException
errors from things such asint.Parse
and wants to makeint.TryParse
their standard - Due to large files and limited memory, your team wants to avoid the
File.ReadAllText
method and use stream-based approaches instead - Your team mandates that all classes must override the
ToString
method to improve the debugging and logging experience
Note that none of these approaches relate to styling or syntax. Instead, these analyzers deal with team-specific decisions about how to best use .NET. We...