GeneratedCodeExtensions Class
internal static class GeneratedCodeExtensionsNo documentation is available.
Methods
| Name | Description |
|---|---|
| HasAutoGeneratedComment(SyntaxNode) | Indicates whether the node starts with a comment containing <auto-generated> or <autogenerated>. Documentation comments are not considered. |
| IsGeneratedCode(SyntaxTree, AnalyzerConfigOptionsProvider, CancellationToken) | Indicates whether the syntax tree is considered as generated code. The generated_code EditorConfig option takes precedence over the heuristics used by GeneratedCodeExtensions.IsGeneratedCode. |
| IsGeneratedCode(SyntaxTree, AnalyzerOptions, CancellationToken) | Indicates whether the syntax tree is considered as generated code. The generated_code EditorConfig option takes precedence over the heuristics used by GeneratedCodeExtensions.IsGeneratedCode. |
| IsGeneratedCode(SyntaxTree, CancellationToken) | Indicates whether the syntax tree is considered as generated code, using the same heuristics as the Roslyn analyzer driver: the file name of SyntaxTree.FilePath or an <auto-generated> comment at the beginning of the file. |
| IsGeneratedCodeFile(string?) | Indicates whether the file name of the path is one of the well-known generated file names, such as Sample.g.cs or Sample.designer.cs. |
| IsGeneratedCodeSymbol(ISymbol, Compilation) | Indicates whether the symbol is considered as generated code, using the same heuristics as the Roslyn analyzer driver: the symbol, or one of the symbols containing it, is decorated with [System.CodeDom.Compiler.GeneratedCode]. |
| IsGeneratedCodeSymbol(ISymbol, INamedTypeSymbol?) | Indicates whether the symbol is considered as generated code, using the same heuristics as the Roslyn analyzer driver: the symbol, or one of the symbols containing it, is decorated with generatedCodeAttribute. Use this overload to resolve the attribute type once instead of once per symbol. |
HasAutoGeneratedComment(SyntaxNode)
Indicates whether the node starts with a comment containing <auto-generated> or <autogenerated>. Documentation comments are not considered.
public static bool HasAutoGeneratedComment(this SyntaxNode node)IsGeneratedCode overloads
IsGeneratedCode(SyntaxTree, AnalyzerConfigOptionsProvider, CancellationToken)
Indicates whether the syntax tree is considered as generated code. The generated_code EditorConfig option takes precedence over the heuristics used by GeneratedCodeExtensions.IsGeneratedCode.
public static bool IsGeneratedCode(this SyntaxTree syntaxTree, AnalyzerConfigOptionsProvider optionsProvider, CancellationToken cancellationToken)Parameters
syntaxTreeSyntaxTreeoptionsProviderAnalyzerConfigOptionsProvidercancellationTokenCancellationToken
Returns
IsGeneratedCode(SyntaxTree, AnalyzerOptions, CancellationToken)
Indicates whether the syntax tree is considered as generated code. The generated_code EditorConfig option takes precedence over the heuristics used by GeneratedCodeExtensions.IsGeneratedCode.
public static bool IsGeneratedCode(this SyntaxTree syntaxTree, AnalyzerOptions analyzerOptions, CancellationToken cancellationToken)Parameters
syntaxTreeSyntaxTreeanalyzerOptionsAnalyzerOptionscancellationTokenCancellationToken
Returns
IsGeneratedCode(SyntaxTree, CancellationToken)
Indicates whether the syntax tree is considered as generated code, using the same heuristics as the Roslyn analyzer driver: the file name of SyntaxTree.FilePath or an <auto-generated> comment at the beginning of the file.
public static bool IsGeneratedCode(this SyntaxTree syntaxTree, CancellationToken cancellationToken)IsGeneratedCodeFile(string?)
IsGeneratedCodeSymbol overloads
IsGeneratedCodeSymbol(ISymbol, Compilation)
Indicates whether the symbol is considered as generated code, using the same heuristics as the Roslyn analyzer driver: the symbol, or one of the symbols containing it, is decorated with [System.CodeDom.Compiler.GeneratedCode].
public static bool IsGeneratedCodeSymbol(this ISymbol symbol, Compilation compilation)Parameters
symbolISymbol- The symbol to inspect, along with the symbols containing it.
compilationCompilation- The compilation the symbol belongs to, used to resolve the attribute type.
Returns
Remarks
A symbol declared in more than one file, such as a partial type, is never considered as generated code, and the walk stops there instead of continuing with the containing symbols. Namespaces are skipped, as they carry no attribute and are almost always declared more than once. The walk ends with the assembly, so an [assembly: GeneratedCode] attribute makes every symbol of the assembly generated code. This complements GeneratedCodeExtensions.IsGeneratedCode, which only looks at the file.
IsGeneratedCodeSymbol(ISymbol, INamedTypeSymbol?)
Indicates whether the symbol is considered as generated code, using the same heuristics as the Roslyn analyzer driver: the symbol, or one of the symbols containing it, is decorated with generatedCodeAttribute. Use this overload to resolve the attribute type once instead of once per symbol.
public static bool IsGeneratedCodeSymbol(this ISymbol symbol, INamedTypeSymbol? generatedCodeAttribute)Parameters
symbolISymbol- The symbol to inspect, along with the symbols containing it.
generatedCodeAttributeINamedTypeSymbol?- The
System.CodeDom.Compiler.GeneratedCodeAttributetype of the compilation. Whennull, no symbol is considered as generated code, which is what happens when the compilation cannot resolve the type.