/
XamlParseException.cs
59 lines (49 loc) · 1.6 KB
/
XamlParseException.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Xml;
namespace Xamarin.Forms.Xaml
{
#if NETSTANDARD2_0
[Serializable]
#endif
public class XamlParseException : Exception
{
readonly string _unformattedMessage;
public XamlParseException()
{
}
public XamlParseException(string message)
: base(message)
{
}
public XamlParseException(string message, Exception innerException)
: base(message, innerException)
{
}
#if NETSTANDARD2_0
protected XamlParseException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
internal XamlParseException(string message, IServiceProvider serviceProvider, Exception innerException = null)
: this(message, GetLineInfo(serviceProvider), innerException)
{
}
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 => _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);
}
static IXmlLineInfo GetLineInfo(IServiceProvider serviceProvider)
=> (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) is IXmlLineInfoProvider lineInfoProvider) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
}
}