I am exploring how to set up Roslyn analyzers for a custom library. The purpose of the analyzer is to ensure correct usage of this custom library that can otherwise not be checked at compile time. Therefore, using the analyzer on its own makes not much sense. However, all online resources on this topic I could find use stringly typed references:
Example from Microsoft’s documentation:
if (!memberSymbol?.ToString().
StartsWith("System.Text.RegularExpressions.Regex.Match") ?? true) return;
I am wondering why that is and whether for an analyzer that is only checking the usage of a specific library, it would be sense to refer to types in a type-safe way using nameof()
/ typeof()
? Is there any technical or other reason not to do that?
I want to avoid some identifiers being renamed and the analyzers just silently stopping to work without notice.