Files
ChatBot/ChatBot/Common/Results/Result.cs
Leonid Pershin 7a3a0172cf many fixes
2025-10-16 07:11:30 +03:00

40 lines
1.0 KiB
C#

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);
}
}