Location Class

Represents the location of a dependency value in a source file, providing the ability to update the value in place.

public abstract class Location

Remarks

A location remembers the value it holds: the value reported with it when the dependency was scanned, then the last value it wrote. An update checks that the file still holds that value before writing, even when no expected value is given, so a file modified since the scan is never overwritten blindly.

Constructors

NameDescription
Location(IFileSystem, string)

Location(IFileSystem, string)

Location.cs
protected Location(IFileSystem fileSystem, string filePath)

Parameters

fileSystem IFileSystem
filePath string

No documentation is available.

Properties

NameDescription
FilePathGets the path of the file containing the dependency.
FileSystem
IsUpdatableGets a value indicating whether this location can be updated.

FilePath

Location.cs

Gets the path of the file containing the dependency.

public string FilePath { get; }

Property value

string

FileSystem

Location.cs
protected IFileSystem FileSystem { get; }

Property value

IFileSystem

No documentation is available.

IsUpdatable

Gets a value indicating whether this location can be updated.

public abstract bool IsUpdatable { get; }

Property value

bool

Methods

NameDescription
UpdateAsync(string?, string, CancellationToken)Updates the value at this location in the source file.
UpdateAsync(string, CancellationToken)Updates the value at this location in the source file, after checking that it still holds the value the location holds.
UpdateCoreAsync(string?, string, CancellationToken)When overridden in a derived class, performs the actual update operation.

UpdateAsync overloads

UpdateAsync(string?, string, CancellationToken)

Location.cs

Updates the value at this location in the source file.

net10.0

public Task UpdateAsync(string? oldValue, string newValue, CancellationToken cancellationToken = default)

net11.0

public Task UpdateAsync(string? oldValue, string newValue, CancellationToken cancellationToken = default)
Parameters
oldValue string?
The expected current value, used for validation. When null, the value the location holds is expected: the value reported by the scan, or the last value written through this location.
newValue string
The new value to write.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task

Exceptions
InvalidOperationException
Thrown when the 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 value at this location anymore.

UpdateAsync(string, CancellationToken)

Location.cs

Updates the value at this location in the source file, after checking that it still holds the value the location holds.

public Task UpdateAsync(string newValue, CancellationToken cancellationToken = default)
Parameters
newValue string
The new value to write.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task

Exceptions
InvalidOperationException
Thrown when the 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 value at this location anymore.

UpdateCoreAsync(string?, string, CancellationToken)

When overridden in a derived class, performs the actual update operation.

protected internal abstract Task UpdateCoreAsync(string? oldValue, string newValue, CancellationToken cancellationToken)

Parameters

oldValue string?
The expected current value, used for validation. It is null only when the caller gave no expected value and the location does not know the value it holds.
newValue string
The new value to write.
cancellationToken CancellationToken
A token to cancel the operation.

Returns

Task