Skip to content

Instantly share code, notes, and snippets.

@feanz
Last active December 20, 2015 19:39
Show Gist options
  • Save feanz/6184813 to your computer and use it in GitHub Desktop.
Save feanz/6184813 to your computer and use it in GitHub Desktop.
Operation Status Object could be returned from persistence layer.
[DebuggerDisplay("Status: {Status}")]
public class OperationStatus
{
public bool Status { get; set; }
public int RecordsAffected { get; set; }
public string Message { get; set; }
public Object OperationId { get; set; }
//Store simple string for exception message to avoid any possible serialization issues
public string ExceptionMessage { get; set; }
public string ExceptionStackTrace { get; set; }
public string ExceptionInnerMessage { get; set; }
public string ExceptionInnerStackTrace { get; set; }
public static OperationStatus CreateFromException(string message, Exception exception)
{
var opStatus = new OperationStatus
{
Status = false,
Message = message,
OperationId = null
};
if (exception != null)
{
opStatus.ExceptionMessage = exception.Message;
opStatus.ExceptionStackTrace = exception.StackTrace;
opStatus.ExceptionInnerMessage = (exception.InnerException != null) ? exception.InnerException.Message : null;
opStatus.ExceptionInnerStackTrace = (exception.InnerException != null) ? exception.InnerException.StackTrace : null;
}
return opStatus;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment