GeneratedCodeExtensions Class

internal static class GeneratedCodeExtensions

No documentation is available.

Methods

NameDescription
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)

Parameters

node SyntaxNode

Returns

bool

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
syntaxTree SyntaxTree
optionsProvider AnalyzerConfigOptionsProvider
cancellationToken CancellationToken
Returns

bool

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
syntaxTree SyntaxTree
analyzerOptions AnalyzerOptions
cancellationToken CancellationToken
Returns

bool

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)
Parameters
syntaxTree SyntaxTree
cancellationToken CancellationToken
Returns

bool

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.

public static bool IsGeneratedCodeFile(string? filePath)

Parameters

filePath string?

Returns

bool

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
symbol ISymbol
The symbol to inspect, along with the symbols containing it.
compilation Compilation
The compilation the symbol belongs to, used to resolve the attribute type.
Returns

bool

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
symbol ISymbol
The symbol to inspect, along with the symbols containing it.
generatedCodeAttribute INamedTypeSymbol?
The System.CodeDom.Compiler.GeneratedCodeAttribute type of the compilation. When null, no symbol is considered as generated code, which is what happens when the compilation cannot resolve the type.
Returns

bool