Class ParseResult<T>
The result of a parse operation.
Inheritance
ParseResult<T>
Assembly: NodaTime.dll
Syntax
public sealed class ParseResult<T>
Type Parameters
Name |
Description |
T |
The type which was parsed, such as a LocalDateTime. |
Properties
Exception
Gets an exception indicating the cause of the parse failure.
Declaration
public Exception Exception { get; }
Property Value
Type |
Description |
Exception |
The exception indicating the cause of the parse failure. (The value returned is never null.) |
Exceptions
Success
Indicates whether the parse operation was successful.
Declaration
public bool Success { get; }
Property Value
Type |
Description |
Boolean |
true if the parse operation was successful; otherwise false. |
Value
Gets the value from the parse operation if it was successful, or throws an exception indicating the parse failure
otherwise.
Declaration
Property Value
Type |
Description |
T |
The result of the parsing operation if it was successful. |
Methods
Convert<TTarget>(Func<T, TTarget>)
Converts this result to a new target type, either by executing the given projection
for a success result, or propagating the exception provider for failure.
Declaration
public ParseResult<TTarget> Convert<TTarget>(Func<T, TTarget> projection)
Parameters
Type |
Name |
Description |
Func<T, TTarget> |
projection |
The projection to apply for the value of this result,
if it's a success result. |
Returns
Type |
Description |
ParseResult<TTarget> |
A ParseResult for the target type, either with a value obtained by applying the specified
projection to the value in this result, or with the same error as this result. (The value returned is never null.) |
Type Parameters
Exceptions
ConvertError<TTarget>()
Converts this result to a new target type by propagating the exception provider.
This parse result must already be an error result.
Declaration
public ParseResult<TTarget> ConvertError<TTarget>()
Returns
Type |
Description |
ParseResult<TTarget> |
A ParseResult for the target type, with the same error as this result. (The value returned is never null.) |
Type Parameters
ForException(Func<Exception>)
Produces a ParseResult which represents a failed parsing operation.
Declaration
public static ParseResult<T> ForException(Func<Exception> exceptionProvider)
Parameters
Type |
Name |
Description |
Func<Exception> |
exceptionProvider |
A delegate that produces the exception representing the error that
caused the parse to fail. |
Returns
Type |
Description |
ParseResult<T> |
A ParseResult representing a failed parsing operation. (The value returned is never null.) |
Exceptions
ForValue(T)
Produces a ParseResult which represents a successful parse operation.
Declaration
public static ParseResult<T> ForValue(T value)
Parameters
Type |
Name |
Description |
T |
value |
The successfully parsed value. |
Returns
Type |
Description |
ParseResult<T> |
A ParseResult representing a successful parsing operation. (The value returned is never null.) |
GetValueOrThrow()
Gets the value from the parse operation if it was successful, or throws an exception indicating the parse failure
otherwise.
Declaration
public T GetValueOrThrow()
Returns
Type |
Description |
T |
The result of the parsing operation if it was successful. |
TryGetValue(T, out T)
Returns the success value, and sets the out parameter to either
the specified failure value of T or the successful parse result value.
Declaration
public bool TryGetValue(T failureValue, out T result)
Parameters
Type |
Name |
Description |
T |
failureValue |
The "default" value to set in result if parsing failed. |
T |
result |
The parameter to store the parsed value in on success. |
Returns
Type |
Description |
Boolean |
True if this parse result was successful, or false otherwise. |