Table of Contents

Class ExtensionMethods

Namespace
InteractiveReadLine
Assembly
InteractiveReadLine.dll

Provides methods that drive a provider through one line of input. Each method runs the interaction through a handler and disposes the provider before returning.

public static class ExtensionMethods
Inheritance
ExtensionMethods
Inherited Members

Methods

Read(IReadLineProvider, ReadLineConfig?, CancellationToken)

Interactively reads a line of text from the provider and returns a result that describes the text and how the user ended the interaction. The method disposes the provider before returning.

public static ReadLineResult Read(this IReadLineProvider provider, ReadLineConfig? config = null, CancellationToken cancellationToken = default)

Parameters

provider IReadLineProvider

the IReadLineProvider provider which will perform the interaction with the user (for example, the ConsoleReadLine object which wraps System.Console)

config ReadLineConfig

The configuration to use for this specific interaction

cancellationToken CancellationToken

A token that cancels the read. The provider is still disposed if the read is canceled, so the console is left in the state it would have been after an ordinary read.

Returns

ReadLineResult

The completed interaction result.

Exceptions

OperationCanceledException

The token was canceled before input completed.

ReadAsync(IReadLineProvider, ReadLineConfig?, CancellationToken)

Interactively reads a line of text from the provider without blocking a thread while waiting for keys, returning a result that describes the text and how the user ended the interaction. The method disposes the provider before returning.

public static Task<ReadLineResult> ReadAsync(this IReadLineProvider provider, ReadLineConfig? config = null, CancellationToken cancellationToken = default)

Parameters

provider IReadLineProvider

the IReadLineProvider provider which will perform the interaction with the user (for example, the ConsoleReadLine object which wraps System.Console)

config ReadLineConfig

The configuration to use for this specific interaction

cancellationToken CancellationToken

A token that cancels the read. The provider is still disposed if the read is canceled, so the console is left in the state it would have been after an ordinary read.

Returns

Task<ReadLineResult>

The completed interaction result.

Exceptions

OperationCanceledException

The token was canceled before input completed.

ReadLine(IReadLineProvider, ReadLineConfig?, CancellationToken)

Interactively read a line of text from the provider, using a specified configuration if one is given as an optional argument.

public static string? ReadLine(this IReadLineProvider provider, ReadLineConfig? config = null, CancellationToken cancellationToken = default)

Parameters

provider IReadLineProvider

the IReadLineProvider provider which will perform the interaction with the user (for example, the ConsoleReadLine object which wraps System.Console)

config ReadLineConfig

The configuration to use for this specific interaction

cancellationToken CancellationToken

A token that cancels the read.

Returns

string

The text read from the user; null if the user signaled the end of input; or an empty string if the user abandoned the line. Use Read to distinguish an abandoned line from an entered empty line.

Exceptions

OperationCanceledException

The token was canceled before input completed.

ReadLineAsync(IReadLineProvider, ReadLineConfig?, CancellationToken)

Interactively reads a line of text from the provider without blocking a thread while waiting for keys. The method disposes the provider before returning.

public static Task<string?> ReadLineAsync(this IReadLineProvider provider, ReadLineConfig? config = null, CancellationToken cancellationToken = default)

Parameters

provider IReadLineProvider

the IReadLineProvider provider which will perform the interaction with the user (for example, the ConsoleReadLine object which wraps System.Console)

config ReadLineConfig

The configuration to use for this specific interaction

cancellationToken CancellationToken

A token that cancels the read.

Returns

Task<string>

The text read from the user; null if the user signaled the end of input; or an empty string if the user abandoned the line. Use ReadAsync to distinguish an abandoned line from an entered empty line.

Exceptions

OperationCanceledException

The token was canceled before input completed.