Innovenergy_trunk/csharp/app/Backend/Utils/Result.cs

29 lines
698 B
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
namespace Backend.Utils;
public class Result
{
private const String OkMsg = "Ok";
private readonly String _Error;
public static Result Ok = new Result(OkMsg);
public Boolean IsError => _Error != OkMsg;
public Boolean IsSuccess => _Error == OkMsg;
private Result(String error) => _Error = error;
public static Result Error(String error) => new Result(error);
public static Result Error(Exception exception)
{
#if DEBUG
var msg = exception.ToString(); // includes stacktrace
#else
var msg = exception.Message; // excludes stacktrace
#endif
return new Result(msg);
}
}