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

29 lines
714 B
C#

namespace InnovEnergy.App.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);
}
}