Dependency Class
Represents a dependency discovered during scanning, including its name, version, type, and location information.
public sealed class DependencyConstructors
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the Dependency class.
public Dependency(string? name, string? version, DependencyType type, Location? nameLocation, Location? versionLocation)Parameters
namestring?- The name of the dependency.
versionstring?- The version of the dependency.
typeDependencyType- The type of the dependency.
nameLocationLocation?- The location of the name. Unless it already knows the value it holds, it records
nameas the value an update expects to find. versionLocationLocation?- The location of the version. Unless it already knows the value it holds, it records
versionas the value an update expects to find.
Dependency(string?, string?, string?, DependencyType, Location?, Location?, Location?)
Dependency.csInitializes 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
namestring?- The name of the dependency.
rawVersionstring?- The version as written where the dependency is declared, such as
$(XunitVersion), ornullwhen the declaration has no version text. resolvedVersionstring?- The version once its variables or properties are replaced with their values, such as
2.9.3, ornullwhen it cannot be resolved. typeDependencyType- The type of the dependency.
nameLocationLocation?- The location of the name. Unless it already knows the value it holds, it records
nameas the value an update expects to find. rawVersionLocationLocation?- The location of
rawVersionwhere the dependency is declared. Unless it already knows the value it holds, it recordsrawVersionas the value an update expects to find. resolvedVersionLocationLocation?- The location of
resolvedVersion: the definition of the property when the version comes from one, or the same location asrawVersionLocationwhen the version is a literal.nullwhen 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 recordsresolvedVersionas the value an update expects to find.
Properties
| Name | Description |
|---|---|
| Metadata | Gets a dictionary of metadata associated with this dependency for storing additional scanner-specific information. |
| Name | Gets the name of the dependency, as found by the scan. It does not change when the name is updated. |
| NameLocation | Gets the location of the dependency name in the source file, or null if not available. |
| RawVersion | Gets the version as written where the dependency is declared, such as $(XunitVersion) or ${junit.version}. |
| RawVersionLocation | Gets the location of Dependency.RawVersion where the dependency is declared, such as the Version="$(XunitVersion)" attribute, or null if not available. |
| ResolvedVersion | Gets the version once its variables or properties are replaced with their values, such as 2.9.3 for $(XunitVersion). |
| ResolvedVersionLocation | Gets the location of Dependency.ResolvedVersion, such as the definition of the property the version comes from, or null if not available. |
| Tags | Gets a collection of tags associated with this dependency, such as the scanner type that discovered it. |
| Type | Gets the type of the dependency. |
| Version | Gets the version of the dependency, as found by the scan. It does not change when the version is updated. |
| VersionLocation | Gets the location to update the version of the dependency, or null if not available. |
Metadata
Dependency.csGets a dictionary of metadata associated with this dependency for storing additional scanner-specific information.
public IDictionary<string, object?> Metadata { get; }Property value
Name
Dependency.csNameLocation
Dependency.csRawVersion
Dependency.csGets the version as written where the dependency is declared, such as $(XunitVersion) or ${junit.version}.
public string? RawVersion { get; }Property value
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.csGets 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
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.csGets 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
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.csGets 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
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).
Tags
Dependency.csGets a collection of tags associated with this dependency, such as the scanner type that discovered it.
Property value
Type
Dependency.csVersion
Dependency.csGets 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
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.csGets the location to update the version of the dependency, or null if not available.
public Location? VersionLocation { get; }Property value
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
| Name | Description |
|---|---|
| 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.csUpdateNameAsync(string, CancellationToken)
Dependency.csUpdates the dependency name in the source file.
public Task UpdateNameAsync(string newValue, CancellationToken cancellationToken = default)Parameters
newValuestring- The new name value to write.
cancellationTokenCancellationToken- A token to cancel the operation.
Returns
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.csUpdates the dependency version in the source file.
public Task UpdateVersionAsync(string newValue, CancellationToken cancellationToken = default)Parameters
newValuestring- The new version value to write.
cancellationTokenCancellationToken- A token to cancel the operation.
Returns
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.