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 LocationRemarks
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
| Name | Description |
|---|---|
| Location(IFileSystem, string) |
Location(IFileSystem, string)
Location.csprotected Location(IFileSystem fileSystem, string filePath)Parameters
fileSystemIFileSystemfilePathstring
No documentation is available.
Properties
| Name | Description |
|---|---|
| FilePath | Gets the path of the file containing the dependency. |
| FileSystem | |
| IsUpdatable | Gets a value indicating whether this location can be updated. |
FilePath
Location.csFileSystem
Location.csIsUpdatable
Methods
| Name | Description |
|---|---|
| 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.csUpdates 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
oldValuestring?- 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. newValuestring- The new value to write.
cancellationTokenCancellationToken- A token to cancel the operation.
Returns
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.csUpdates 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
newValuestring- The new value to write.
cancellationTokenCancellationToken- A token to cancel the operation.
Returns
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
oldValuestring?- The expected current value, used for validation. It is
nullonly when the caller gave no expected value and the location does not know the value it holds. newValuestring- The new value to write.
cancellationTokenCancellationToken- A token to cancel the operation.