/// <summary>
 /// Initializes a new instance of the <see cref="ParsedException"/> class.
 /// </summary>
 /// <param name="error">Error object.</param>
 public ParsedException(XmlErrorResponse error)
 {
     this.Code       = error.Code;
     this.InnerError = error.InnerError;
     this.Message    = error.Message;
     this.Values     = error.Values;
 }
        /// <summary>
        /// Parses the specified exception.
        /// </summary>
        /// <param name="ex">Exception to parse.</param>
        /// <returns>Parsed exception.</returns>
        /// <exception cref="ArgumentNullException">Exception is null.</exception>
        /// <exception cref="ArgumentException">Exception is not of type InvalidOperationException.</exception>
        public static ParsedException Parse(Exception ex)
        {
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }

            if (!(ex is InvalidOperationException))
            {
                throw new ArgumentException("Exception is not of type InvalidOperationException", "ex");
            }

            ParsedException parsedException = new ParsedException();

            string messageToBeParsed = ex.Message;

            if (ex.InnerException != null)
            {
                messageToBeParsed = ex.InnerException.Message;
            }

            try
            {
                StringReader     stringReader = new StringReader(messageToBeParsed);
                XmlErrorResponse errorObject  =
                    ParsedException.xmlSerializer.Deserialize(stringReader) as XmlErrorResponse;
                parsedException = new ParsedException(errorObject);
            }
            catch (InvalidOperationException)
            {
            }

            if (String.IsNullOrEmpty(parsedException.Code))
            {
                parsedException.Code = messageToBeParsed;
            }

            return(parsedException);
        }