using System;
using System.Xml;
using System.Xml.Linq;
namespace OpenTap
{
/// Contains detailed information about what went wrong while loading or saving information to an XML file.
public class XmlError : XmlMessage
{
/// The exception that occured - if any.
public virtual Exception Exception { get; }
/// Creates an instance of XmlError. xmlElement may be null. message may be null if exception is set.
public XmlError(XElement xmlElement, string message, Exception exception = null) : base(xmlElement, message)
{
Exception = exception;
}
/// Prints this error in a readable fashion.
public override string ToString()
{
string message = Message ?? Exception.Message;
if (Element is IXmlLineInfo lineInfo && lineInfo.HasLineInfo())
return $"XML Line {lineInfo.LineNumber}: {message}";
if (Exception is XmlException x)
return $"XML Line {x.LineNumber}: {message}";
return message;
}
}
}