Table of Contents

ConfigurationSourceLocation Struct

Definition

Namespace
Bodu.Text.Configuration
Assembly
Bodu.Text.Configuration.dll
Package
Bodu.Text.Configuration 1.0.0
Source
ConfigurationSourceLocation.cs

Identifies a specific position in a configuration source document so that diagnostics, exceptions, and model elements can point back to the originating line and column.

public readonly struct ConfigurationSourceLocation : IEquatable<ConfigurationSourceLocation>
Implements
Inherited Members
Extension Methods

Examples

// Construct a location pointing at a specific span on line 12.
var loc = new ConfigurationSourceLocation(
    lineNumber:   12,
    linePosition: 5,
    length:       8,
    path:         "app.ini");
Console.WriteLine(loc);   // "app.ini(12,5): length 8"

// Surface from a parse exception in editor-style form.
try { ConfigurationDocument.Parse(text); }
catch (ConfigurationParseException ex)
{
    ConfigurationSourceLocation where = ex.Location;
    if (!where.Equals(ConfigurationSourceLocation.None))
        Console.WriteLine($"{where}: {ex.Message}");
}

Remarks

Locations are 1-based for both LineNumber and LinePosition, matching the convention used by most editors and diagnostic UIs. A Length of zero indicates an unsized point; non-zero indicates a span that begins at LinePosition and runs for Length characters within the same line.

Path is set only when the configuration document was loaded from a file. Documents parsed from strings expose null here.

None is the canonical "unknown" location and compares equal to a default-constructed instance. The type is a readonly struct and is safe to pass by value across diagnostic and exception boundaries; ToString() renders the location in line N, column M form suitable for log output and IDE error lists.

Constructors

ConfigurationSourceLocation(int, int, int, string?)

Initializes a new instance of the ConfigurationSourceLocation struct with the specified line number, column, span length, and optional file path.

public ConfigurationSourceLocation(int lineNumber, int linePosition, int length, string? path = null)

Parameters

lineNumber int

The 1-based line number.

linePosition int

The 1-based column within the line.

length int

The length of the span in characters.

path string

The optional source file path.

Properties

Length

Gets the length of the span, measured in characters within the same line.

public int Length { get; }

Property Value

int

A non-negative count; zero indicates a point location.

LineNumber

Gets the 1-based line number that identifies the line in the source document.

public int LineNumber { get; }

Property Value

int

A positive line number, or zero when the location is unknown.

LinePosition

Gets the 1-based column within LineNumber at which the span starts.

public int LinePosition { get; }

Property Value

int

A positive column number, or zero when the column is unknown.

None

Gets a location that represents an unknown position.

public static ConfigurationSourceLocation None { get; }

Property Value

ConfigurationSourceLocation

An empty location whose numeric fields are all zero.

Path

Gets the source file path that produced this location, or null when the document was parsed from an in-memory string.

public string? Path { get; }

Property Value

string

The optional source path.

Methods

Equals(ConfigurationSourceLocation)

Determines whether two locations refer to the same position in the same source.

public bool Equals(ConfigurationSourceLocation other)

Parameters

other ConfigurationSourceLocation

The location to compare with this instance.

Returns

bool

true if every field matches; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns a human-readable rendering of the location, suitable for inclusion in diagnostic messages.

public override string ToString()

Returns

string

A string of the form line N, column M, optionally prefixed with the path.

Operators

operator ==(ConfigurationSourceLocation, ConfigurationSourceLocation)

Determines whether two locations are equal.

public static bool operator ==(ConfigurationSourceLocation left, ConfigurationSourceLocation right)

Parameters

left ConfigurationSourceLocation

The first location to compare.

right ConfigurationSourceLocation

The second location to compare.

Returns

bool

true if the locations are equal; otherwise, false.

operator !=(ConfigurationSourceLocation, ConfigurationSourceLocation)

Determines whether two locations are not equal.

public static bool operator !=(ConfigurationSourceLocation left, ConfigurationSourceLocation right)

Parameters

left ConfigurationSourceLocation

The first location to compare.

right ConfigurationSourceLocation

The second location to compare.

Returns

bool

true if the locations differ; otherwise, false.

Applies to

ProductVersions
.NET8, 10