Skip to content

OnixLabs.Core.ISpanParsableExtensions

Matthew Layton edited this page Nov 15, 2026 · 2 revisions

ISpanParsableExtensions Class

Extension methods for ISpanParsable<TSelf> types, providing a throwing parse helper.

Namespace OnixLabs.Core
Assembly OnixLabs.Core.dll (NuGet)
Inheritance object → ISpanParsableExtensions

Definition

[EditorBrowsable(EditorBrowsableState.Never)]
public static class ISpanParsableExtensions

Note This class is decorated with [EditorBrowsable(EditorBrowsableState.Never)], which keeps the container class itself out of IntelliSense lists while its extension methods remain fully usable on the receiver types. Bring the methods into scope with using OnixLabs.Core;.

Remarks

ISpanParsableExtensions exposes a ParseOrThrow static helper directly on the type T (via the generic constraint where T : ISpanParsable<T>), offering a concise parse-or-throw pattern without requiring a separate try/catch block.

Methods

Method Returns Description
ParseOrThrow<T>(ReadOnlySpan<char>, IFormatProvider?) T Parses the specified value, or throws a FormatException if it cannot be parsed.

ParseOrThrow<T>(ReadOnlySpan<char>, IFormatProvider?)

public static T ParseOrThrow<T>(ReadOnlySpan<char> value, IFormatProvider? provider = null)
    where T : ISpanParsable<T>

Tries to parse the specified value using T.TryParse, or throws a FormatException if the value cannot be parsed. This is a static member exposed on the type T itself.

Parameter Type Description
value ReadOnlySpan<char> The value to parse.
provider IFormatProvider? An object that provides culture-specific formatting information about the value. Defaults to null.

Returns — A new instance of T parsed from the specified value.

Exceptions

Exception Condition
FormatException The value cannot be parsed.
int number = int.ParseOrThrow("123"); // 123
Guid id = Guid.ParseOrThrow("00000000-0000-0000-0000-000000000000");

See Also

ONIXLabs .NET Library


Clone this wiki locally