12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
-
- namespace Luticate2.Utils.Dbo
- {
- public class LuResult<T>
- {
- public LuStatus Status { get; set; }
-
- public bool Success => Status == LuStatus.Success;
-
- 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<T> Ok(T data)
- {
- return new LuResult<T>
- {
- StackTrace = new Exception().StackTrace,
- Data = data,
- Status = LuStatus.Success
- };
- }
-
- public static LuResult<T> Error(LuStatus status, string privateDetails, string publicDetails = null)
- {
- return new LuResult<T>
- {
- PublicDetails = publicDetails == "" ? privateDetails : publicDetails,
- PrivateDetails = privateDetails,
- StackTrace = new Exception().StackTrace,
- Status = status
- };
- }
-
- public static LuResult<T> Error(LuStatus status, Exception e, string publicDetails = null)
- {
- return Error(status, e.ToString(), publicDetails);
- }
-
- public static LuResult<T> Error<T2>(LuResult<T2> other)
- {
- return new LuResult<T>
- {
- Status = other.Status,
- PublicDetails = other.PublicDetails,
- PrivateDetails = other.PrivateDetails,
- StackTrace = other.StackTrace,
- Exception = other.Exception
- };
- }
-
- public LuResult<T2> To<T2>()
- {
- return LuResult<T2>.Error(this);
- }
-
- public static implicit operator bool(LuResult<T> res)
- {
- return res.Success;
- }
- }
- }
|