ScannerOptions Class

Provides configuration options for dependency scanning operations.

var options = new ScannerOptions
{
    DegreeOfParallelism = 8,
    RecurseSubdirectories = true,
    IncludedDependencyTypes = [DependencyType.NuGet, DependencyType.Npm],
};
var dependencies = await DependencyScanner.ScanDirectoryAsync("C:\\MyProject", options, cancellationToken);
public sealed class ScannerOptions

Constructors

NameDescription
ScannerOptions()

ScannerOptions()

ScannerOptions.cs
public ScannerOptions()

No documentation is available.

Properties

NameDescription
DegreeOfParallelismGets or sets the maximum number of parallel scanning tasks, or -1 to use Environment.ProcessorCount. Default is 16.
ExcludedDependencyTypesGets or sets the set of dependency types to exclude from scanning. Default is empty (no types excluded).
FileSystemGets or sets the file system implementation to use for file access.
IncludedDependencyTypesGets or sets the set of dependency types to include. When set, only these types will be scanned. Default is empty (all types included).
OnFileScanFailedGets or sets the callback invoked when a file cannot be scanned. Default is null: the file is silently skipped.
RecurseSubdirectoriesGets or sets a value indicating whether to recurse into subdirectories. Default is true.
ScannersGets or sets the collection of scanners to use. Defaults to all built-in scanners.
ShouldRecursePredicateGets or sets a predicate to filter which subdirectories to recurse into.
ShouldScanFilePredicateGets or sets a predicate to filter which files to scan.

DegreeOfParallelism

ScannerOptions.cs

Gets or sets the maximum number of parallel scanning tasks, or -1 to use Environment.ProcessorCount. Default is 16.

public int DegreeOfParallelism { get; set; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is 0 or less than -1.

ExcludedDependencyTypes

ScannerOptions.cs

Gets or sets the set of dependency types to exclude from scanning. Default is empty (no types excluded).

public ImmutableHashSet<DependencyType> ExcludedDependencyTypes { get; set; }

Gets or sets the file system implementation to use for file access.

public IFileSystem FileSystem { get; set; }

Property value

IFileSystem

Remarks

With a custom file system, a directory scan lists the files with IFileSystem.GetFiles using the * pattern, and does not support ScannerOptions.ShouldScanFilePredicate and ScannerOptions.ShouldRecursePredicate.

IncludedDependencyTypes

ScannerOptions.cs

Gets or sets the set of dependency types to include. When set, only these types will be scanned. Default is empty (all types included).

public ImmutableHashSet<DependencyType> IncludedDependencyTypes { get; set; }

OnFileScanFailed

ScannerOptions.cs

Gets or sets the callback invoked when a file cannot be scanned. Default is null: the file is silently skipped.

public FileScanFailed? OnFileScanFailed { get; set; }

Property value

FileScanFailed?

Remarks

A file that cannot be opened or read, or that a scanner fails to scan, is skipped and the scan continues with the next file. The callback receives the path of the file and the exception. It can be invoked concurrently, and an exception it throws stops the scan. Cancellation is not a failure: the scan methods throw an OperationCanceledException when their cancellation token is canceled.

RecurseSubdirectories

ScannerOptions.cs

Gets or sets a value indicating whether to recurse into subdirectories. Default is true.

public bool RecurseSubdirectories { get; set; }

Property value

bool

Gets or sets the collection of scanners to use. Defaults to all built-in scanners.

public ImmutableArray<DependencyScanner> Scanners { get; set; }

ShouldRecursePredicate

ScannerOptions.cs

Gets or sets a predicate to filter which subdirectories to recurse into.

public FileSystemEntryPredicate? ShouldRecursePredicate { get; set; }

Property value

FileSystemEntryPredicate?

Remarks

Symbolic links and other reparse points to directories are never followed, whatever the predicate returns. The predicate is only supported with the default ScannerOptions.FileSystem: a directory scan with a custom file system throws a NotSupportedException when it is set.

ShouldScanFilePredicate

ScannerOptions.cs

Gets or sets a predicate to filter which files to scan.

public FileSystemEntryPredicate? ShouldScanFilePredicate { get; set; }

Property value

FileSystemEntryPredicate?

Remarks

The predicate is only supported with the default ScannerOptions.FileSystem: a directory scan with a custom file system throws a NotSupportedException when it is set.