Interface IErrorFactory<TSelf>
Opt-in interface that enables generic error construction via a static factory method.
Implement on custom error types to participate in Result.Fail<TError>(string).
public interface IErrorFactory<TSelf> where TSelf : IErrorFactory<TSelf>
Type Parameters
TSelfThe implementing error type (CRTP pattern).
Examples
// Instead of: Result<User>.Fail(new NotFoundError("User not found"))
// You can write:
Result<User>.Fail<NotFoundError>("User not found");
// Useful in generic code:
Result<T> NotFound<T, TError>(string message) where TError : IErrorFactory<TError>
=> Result<T>.Fail(TError.Create(message));
Methods
Create(string)
Creates an instance of TSelf with the given message.
public static abstract TSelf Create(string message)
Parameters
messagestring
Returns
- TSelf