many fixes
This commit is contained in:
39
ChatBot/Common/Results/Result.cs
Normal file
39
ChatBot/Common/Results/Result.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace ChatBot.Common.Results
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the result of an operation that can succeed or fail
|
||||
/// </summary>
|
||||
public class Result
|
||||
{
|
||||
public bool IsSuccess { get; }
|
||||
public string Error { get; }
|
||||
|
||||
protected Result(bool isSuccess, string error)
|
||||
{
|
||||
IsSuccess = isSuccess;
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public static Result Success() => new(true, string.Empty);
|
||||
|
||||
public static Result Failure(string error) => new(false, error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the result of an operation that returns a value
|
||||
/// </summary>
|
||||
public class Result<T> : Result
|
||||
{
|
||||
public T? Value { get; }
|
||||
|
||||
private Result(T? value, bool isSuccess, string error)
|
||||
: base(isSuccess, error)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Result<T> Success(T value) => new(value, true, string.Empty);
|
||||
|
||||
public static new Result<T> Failure(string error) => new(default, false, error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user