Class QueryResult<TResult>
Represents the result of a query invokation, which either succeeded with data or failed with an exception.
public record QueryResult<TResult> : IEquatable<QueryResult<TResult>>
Type Parameters
TResult
- Inheritance
-
QueryResult<TResult>
- Implements
-
IEquatable<QueryResult<TResult>>
- Inherited Members
Remarks
This type mostly exists so that methods like TriggerAsync don't need to re-throw the exception directly, which makes them safe to use in Blazor component callbacks.
Constructors
QueryResult(Exception)
Creates a new unsuccessful result.
public QueryResult(Exception error)
Parameters
error
Exception
QueryResult(TResult?)
Creates a new successful result.
public QueryResult(TResult? result)
Parameters
result
TResult
Properties
Data
The result returned by the query if it succeeded, otherwise default.
public TResult? Data { get; }
Property Value
- TResult
Error
The exception thrown by the query if it failed, otherwise null.
public Exception? Error { get; }
Property Value
IsSuccess
Whether or not the query succeeded (completed without throwing an exception).
public bool IsSuccess { get; }
Property Value
Methods
GetOrDefault(TResult)
Returns the query result if the query succeeded, otherwise returns defaultValue
.
public TResult GetOrDefault(TResult defaultValue)
Parameters
defaultValue
TResult
Returns
- TResult
GetOrThrow()
Returns the query result if the query succeeded, otherwise throws the exception thrown by the query.
public TResult GetOrThrow()
Returns
- TResult