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

29 lines
710 B
C#
Raw Normal View History

2023-02-24 11:58:47 +00:00
namespace Innovenergy.Backend.Utils;
2023-02-16 12:57:06 +00:00
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);
}
}