summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/XamlParseException.cs
blob: d953da0f81c159483b2c470f212c6ca86e8d6fbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Xml;

namespace Xamarin.Forms.Xaml
{
	public class XamlParseException : Exception
	{
		readonly string _unformattedMessage;

		public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message, xmlInfo), innerException)
		{
			_unformattedMessage = message;
			XmlInfo = xmlInfo;
		}

		public IXmlLineInfo XmlInfo { get; private set; }

		internal string UnformattedMessage
		{
			get { return _unformattedMessage ?? Message; }
		}

		static string FormatMessage(string message, IXmlLineInfo xmlinfo)
		{
			if (xmlinfo == null || !xmlinfo.HasLineInfo())
				return message;
			return string.Format("Position {0}:{1}. {2}", xmlinfo.LineNumber, xmlinfo.LinePosition, message);
		}
	}
}