using System; namespace Luticate2.Auth.Dbo.Result { public class LuResult { public int Status { get; set; } public bool Success => Status == LuStatus.Success.ToInt(); public string PublicDetails { get; set; } public string PrivateDetails { get; set; } public string StackTrace { get; set; } public Exception Exception { get; set; } public T Data { get; set; } protected LuResult() { } public static LuResult Ok(T data) { return new LuResult { StackTrace = new Exception().StackTrace, Data = data, Status = LuStatus.Success.ToInt() }; } public static LuResult Error(int status, string privateDetails, string publicDetails = null) { return new LuResult { PublicDetails = publicDetails == "" ? privateDetails : publicDetails, PrivateDetails = privateDetails, StackTrace = new Exception().StackTrace, Status = status }; } public static LuResult Error(int status, Exception e, string publicDetails = null) { return new LuResult { PublicDetails = publicDetails, PrivateDetails = e.ToString(), StackTrace = new Exception().StackTrace, Exception = e, Status = status }; } public static LuResult Error(LuResult other) { return new LuResult { Status = other.Status, PublicDetails = other.PublicDetails, PrivateDetails = other.PrivateDetails, StackTrace = other.StackTrace, Exception = other.Exception }; } public LuResult To() { return LuResult.Error(this); } public LuResult To(Func convert) { return new LuResult { Data = Success ? convert(Data) : default(T2), Status = Status, PublicDetails = PublicDetails, PrivateDetails = PrivateDetails, StackTrace = StackTrace, Exception = Exception }; } public static implicit operator bool(LuResult res) { return res.Success; } } }