Dependency Class

Represents a dependency discovered during scanning, including its name, version, type, and location information.

public sealed class Dependency

Constructors

NameDescription
Dependency(string?, string?, DependencyType, Location?, Location?)Initializes a new instance of the Dependency class.
Dependency(string?, string?, string?, DependencyType, Location?, Location?, Location?)Initializes a new instance of the Dependency class for a version that may be written with variables or properties.

Dependency overloads

Dependency(string?, string?, DependencyType, Location?, Location?)

Dependency.cs

Initializes a new instance of the Dependency class.

public Dependency(string? name, string? version, DependencyType type, Location? nameLocation, Location? versionLocation)
Parameters
name string?
The name of the dependency.
version string?
The version of the dependency.
type DependencyType
The type of the dependency.
nameLocation Location?
The location of the name. Unless it already knows the value it holds, it records name as the value an update expects to find.
versionLocation Location?
The location of the version. Unless it already knows the value it holds, it records version as the value an update expects to find.

Dependency(string?, string?, string?, DependencyType, Location?, Location?, Location?)

Dependency.cs

Initializes a new instance of the Dependency class for a version that may be written with variables or properties.

public Dependency(string? name, string? rawVersion, string? resolvedVersion, DependencyType type, Location? nameLocation, Location? rawVersionLocation, Location? resolvedVersionLocation)
Parameters
name string?
The name of the dependency.
rawVersion string?
The version as written where the dependency is declared, such as $(XunitVersion), or null when the declaration has no version text.
resolvedVersion string?
The version once its variables or properties are replaced with their values, such as 2.9.3, or null when it cannot be resolved.
type DependencyType
The type of the dependency.
nameLocation Location?
The location of the name. Unless it already knows the value it holds, it records name as the value an update expects to find.
rawVersionLocation Location?
The location of rawVersion where the dependency is declared. Unless it already knows the value it holds, it records rawVersion as the value an update expects to find.
resolvedVersionLocation Location?
The location of resolvedVersion: the definition of the property when the version comes from one, or the same location as rawVersionLocation when the version is a literal. null when the version cannot be resolved or is not written in one place, such as $(Major).$(Minor). Unless it already knows the value it holds, it records resolvedVersion as the value an update expects to find.

Properties

NameDescription
MetadataGets a dictionary of metadata associated with this dependency for storing additional scanner-specific information.
NameGets the name of the dependency, as found by the scan. It does not change when the name is updated.
NameLocationGets the location of the dependency name in the source file, or null if not available.
RawVersionGets the version as written where the dependency is declared, such as $(XunitVersion) or ${junit.version}.
RawVersionLocationGets the location of Dependency.RawVersion where the dependency is declared, such as the Version="$(XunitVersion)" attribute, or null if not available.
ResolvedVersionGets the version once its variables or properties are replaced with their values, such as 2.9.3 for $(XunitVersion).
ResolvedVersionLocationGets the location of Dependency.ResolvedVersion, such as the definition of the property the version comes from, or null if not available.
TagsGets a collection of tags associated with this dependency, such as the scanner type that discovered it.
TypeGets the type of the dependency.
VersionGets the version of the dependency, as found by the scan. It does not change when the version is updated.
VersionLocationGets the location to update the version of the dependency, or null if not available.

Gets a dictionary of metadata associated with this dependency for storing additional scanner-specific information.

public IDictionary<string, object?> Metadata { get; }

Gets the name of the dependency, as found by the scan. It does not change when the name is updated.

public string? Name { get; }

Property value

string?

NameLocation

Dependency.cs

Gets the location of the dependency name in the source file, or null if not available.

public Location? NameLocation { get; }

Property value

Location?

RawVersion

Dependency.cs

Gets the version as written where the dependency is declared, such as $(XunitVersion) or ${junit.version}.

public string? RawVersion { get; }

Property value

string?

Remarks

It is the same as Dependency.Version when the version is a literal. It is null when the declaration has no version text, such as a version catalog library that references a version with version.ref. It does not change when the version is updated.

RawVersionLocation

Dependency.cs

Gets the location of Dependency.RawVersion where the dependency is declared, such as the Version="$(XunitVersion)" attribute, or null if not available.

public Location? RawVersionLocation { get; }

Property value

Location?

Remarks

It is the same location as Dependency.VersionLocation when the version is a literal. When the version references a property, updating this location replaces the reference, for instance with a literal version to stop using the property for this dependency only.

ResolvedVersion

Dependency.cs

Gets the version once its variables or properties are replaced with their values, such as 2.9.3 for $(XunitVersion).

public string? ResolvedVersion { get; }

Property value

string?

Remarks

It is the same as Dependency.Version when the version is a literal. It is null when the version references a variable or a property whose value is unknown, such as a property defined in another file. It does not change when the version is updated.

ResolvedVersionLocation

Dependency.cs

Gets the location of Dependency.ResolvedVersion, such as the definition of the property the version comes from, or null if not available.

public Location? ResolvedVersionLocation { get; }

Property value

Location?

Remarks

The dependencies that use the same definition share this location instance, so that the value an update writes is the value the next update expects. It is the same location as Dependency.RawVersionLocation when the version is a literal, and null when the version cannot be resolved or is built from several parts, such as $(Major).$(Minor).

Gets a collection of tags associated with this dependency, such as the scanner type that discovered it.

public ISet<string> Tags { get; }

Property value

ISet<string>

Gets the type of the dependency.

public DependencyType Type { get; }

Property value

DependencyType

Gets the version of the dependency, as found by the scan. It does not change when the version is updated.

public string? Version { get; }

Property value

string?

Remarks

It is Dependency.ResolvedVersion when the version can be resolved, and Dependency.RawVersion otherwise, such as $(XunitVersion) when the property is not defined in the file.

VersionLocation

Dependency.cs

Gets the location to update the version of the dependency, or null if not available.

public Location? VersionLocation { get; }

Property value

Location?

Remarks

It is Dependency.ResolvedVersionLocation, such as the definition of the property the version comes from, so that updating the version changes every dependency that uses the property. When the version cannot be resolved, or is not written in one place, it is a location that is not updatable.

Methods

NameDescription
ToString()
UpdateNameAsync(string, CancellationToken)Updates the dependency name in the source file.
UpdateVersionAsync(string, CancellationToken)Updates the dependency version in the source file.

ToString()

Dependency.cs
public override string ToString()

Returns

string

No documentation is available.

UpdateNameAsync(string, CancellationToken)

Dependency.cs

Updates the dependency name in the source file.

public Task UpdateNameAsync(string newValue, CancellationToken cancellationToken = default)

Parameters

newValue string
The new name value to write.
cancellationToken CancellationToken
A token to cancel the operation.

Returns

Task

Exceptions

InvalidOperationException
Thrown when the name location is not updatable.
ArgumentException
The file cannot hold newValue, such as a line break in a line of text, or a control character in an XML file.
DependencyScannerException
The file does not hold the expected name at the location anymore.

Remarks

The file must still hold the value the location holds: the scanned name, or the name written by the previous update. So the name can be updated several times, and the name and the version can be updated in any order.

UpdateVersionAsync(string, CancellationToken)

Dependency.cs

Updates the dependency version in the source file.

public Task UpdateVersionAsync(string newValue, CancellationToken cancellationToken = default)

Parameters

newValue string
The new version value to write.
cancellationToken CancellationToken
A token to cancel the operation.

Returns

Task

Exceptions

InvalidOperationException
Thrown when the version location is not updatable.
ArgumentException
The file cannot hold newValue, such as a line break in a line of text, or a control character in an XML file.
DependencyScannerException
The file does not hold the expected version at the location anymore.

Remarks

The file must still hold the value the location holds: the scanned version, or the version written by the previous update. So the version can be updated several times, and the name and the version can be updated in any order.