123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System;
- using System.Diagnostics;
-
- namespace iiie.Logs.DBO
- {
-
-
-
-
- public class OpResult<T>
- {
-
-
-
- public ResultStatus Status { get; set; }
-
-
-
-
- public bool Success
- {
- get
- {
- return Status == ResultStatus.Success;
- }
- }
-
-
-
-
-
- public string PublicDetails { get; set; }
-
-
-
-
-
- public string PrivateDetails { get; set; }
-
-
-
-
- public StackFrame[] StackFrames { get; set; }
-
-
-
-
- public Exception Exception { get; set; }
-
-
-
-
-
- public T Data { get; set; }
-
-
-
-
-
-
- public static OpResult<T> Ok(T data)
- {
- return new OpResult<T>
- {
- PublicDetails = null,
- PrivateDetails = null,
- StackFrames = new StackTrace().GetFrames(),
- Data = data,
- Status = ResultStatus.Success
- };
- }
-
-
-
-
-
-
-
- public static OpResult<T> Error(ResultStatus status, string privateDetails, string publicDetails = null)
- {
- return new OpResult<T>
- {
- PublicDetails = publicDetails == "" ? privateDetails : publicDetails,
- PrivateDetails = privateDetails,
- StackFrames = new StackTrace().GetFrames(),
- Data = default(T),
- Status = status
- };
- }
-
-
-
-
-
-
-
- public static OpResult<T> Error(ResultStatus status, Exception e, string userDetails = null)
- {
- string message = "";
- Exception inner = e;
- while (inner != null)
- {
- message += inner.GetType().Name + ": " + inner.Message + (inner.InnerException != null ? "\n" : "");
- inner = inner.InnerException;
- }
- var res = Error(status, message, userDetails);
- res.Exception = e;
- return res;
- }
-
-
-
-
-
-
-
- public static OpResult<T> Error<T2>(OpResult<T2> other)
- {
- return new OpResult<T>
- {
- PublicDetails = other.PublicDetails,
- PrivateDetails = other.PrivateDetails,
- StackFrames = other.StackFrames,
- Data = default(T),
- Status = other.Status
- };
- }
-
-
-
-
-
-
- public OpResult<T2> To<T2>()
- {
- return OpResult<T2>.Error(this);
- }
-
-
-
-
-
-
- public static implicit operator bool(OpResult<T> res)
- {
- return res.Success;
- }
-
- protected OpResult()
- {
- }
- }
- }
|