1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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 new LuResult<T>
- {
- PublicDetails = publicDetails,
- PrivateDetails = e.ToString(),
- StackTrace = new Exception().StackTrace,
- Exception = e,
- Status = status
- };
- }
-
- 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;
- }
- }
- }
|