ScanFileContext Struct
Provides context information and methods for scanning a file and reporting discovered dependencies.
public readonly struct ScanFileContext : IAsyncDisposable- Implements
Properties
| Name | Description |
|---|---|
| CancellationToken | Gets the cancellation token for the scanning operation. |
| Content | Gets a seekable stream containing the file content. The stream is lazily opened on first access. |
| FileSystem | Gets the file system implementation for accessing files. |
| FullPath | Gets the full path of the file being scanned. |
CancellationToken
ScanFileContext.csGets the cancellation token for the scanning operation.
public CancellationToken CancellationToken { get; }Property value
Content
ScanFileContext.csGets a seekable stream containing the file content. The stream is lazily opened on first access.
public Stream Content { get; }Property value
Remarks
When the file system returns a stream that cannot seek, the content is read into memory. An exception thrown while opening the file makes the scan skip the file, and is reported to ScannerOptions.OnFileScanFailed.
FileSystem
ScanFileContext.csGets the file system implementation for accessing files.
public IFileSystem FileSystem { get; }Property value
FullPath
ScanFileContext.csMethods
| Name | Description |
|---|---|
| DisposeAsync() | |
| ReportDependency(DependencyScanner, string?, string?, DependencyType, Location?, Location?) | Reports a discovered dependency to the scanning framework. |
| ReportDependency(DependencyScanner, string?, string?, DependencyType, Location?, Location?, ReadOnlySpan<string>, ReadOnlySpan<KeyValuePair<string, object?>>) | Reports a discovered dependency with additional tags and metadata to the scanning framework. |
| ReportDependency(DependencyScanner, string?, string?, string?, DependencyType, Location?, Location?, Location?, ReadOnlySpan<string>, ReadOnlySpan<KeyValuePair<string, object?>>) | Reports a discovered dependency whose version may be written with variables or properties. |
DisposeAsync()
ScanFileContext.csReportDependency overloads
ReportDependency(DependencyScanner, string?, string?, DependencyType, Location?, Location?)
ScanFileContext.csReports a discovered dependency to the scanning framework.
public void ReportDependency(DependencyScanner scanner, string? name, string? version, DependencyType type, Location? nameLocation, Location? versionLocation)Parameters
scannerDependencyScanner- The scanner that discovered the dependency.
namestring?- The name of the dependency.
versionstring?- The version of the dependency.
typeDependencyType- The type of the dependency.
nameLocationLocation?- The location of the dependency name in the source file.
versionLocationLocation?- The location of the dependency version in the source file.
ReportDependency(DependencyScanner, string?, string?, DependencyType, Location?, Location?, ReadOnlySpan<string>, ReadOnlySpan<KeyValuePair<string, object?>>)
ScanFileContext.csReports a discovered dependency with additional tags and metadata to the scanning framework.
public void ReportDependency(DependencyScanner scanner, string? name, string? version, DependencyType type, Location? nameLocation, Location? versionLocation, ReadOnlySpan<string> tags, ReadOnlySpan<KeyValuePair<string, object?>> metadata)Parameters
scannerDependencyScanner- The scanner that discovered the dependency.
namestring?- The name of the dependency.
versionstring?- The version of the dependency.
typeDependencyType- The type of the dependency.
nameLocationLocation?- The location of the dependency name in the source file.
versionLocationLocation?- The location of the dependency version in the source file.
tagsReadOnlySpan<string>- Additional tags to associate with the dependency.
metadataReadOnlySpan<KeyValuePair<string, object?>>- Additional metadata to associate with the dependency.
ReportDependency(DependencyScanner, string?, string?, string?, DependencyType, Location?, Location?, Location?, ReadOnlySpan<string>, ReadOnlySpan<KeyValuePair<string, object?>>)
ScanFileContext.csReports a discovered dependency whose version may be written with variables or properties.
public void ReportDependency(DependencyScanner scanner, string? name, string? rawVersion, string? resolvedVersion, DependencyType type, Location? nameLocation, Location? rawVersionLocation, Location? resolvedVersionLocation, ReadOnlySpan<string> tags, ReadOnlySpan<KeyValuePair<string, object?>> metadata)Parameters
scannerDependencyScanner- The scanner that discovered the dependency.
namestring?- The name of the dependency.
rawVersionstring?- The version as written where the dependency is declared, such as
$(XunitVersion). resolvedVersionstring?- The version once its variables or properties are replaced with their values, or
nullwhen it cannot be resolved. typeDependencyType- The type of the dependency.
nameLocationLocation?- The location of the dependency name in the source file.
rawVersionLocationLocation?- The location of
rawVersionwhere the dependency is declared. resolvedVersionLocationLocation?- The location of
resolvedVersion: the definition of the property when the version comes from one,rawVersionLocationwhen the version is a literal, ornullwhen the version cannot be resolved or is not written in one place. tagsReadOnlySpan<string>- Additional tags to associate with the dependency.
metadataReadOnlySpan<KeyValuePair<string, object?>>- Additional metadata to associate with the dependency.
Remarks
Pass the same location instance for every dependency that uses the same definition, so that the value an update writes is the value the next update expects.