-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
XamlParseException.cs
66 lines (56 loc) · 2.78 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
60
61
62
63
64
65
66
#nullable disable
using System;
using System.Xml;
namespace Microsoft.Maui.Controls.Xaml
{
/// <include file="../../docs/Microsoft.Maui.Controls.Xaml/XamlParseException.xml" path="Type[@FullName='Microsoft.Maui.Controls.Xaml.XamlParseException']/Docs/*" />
[Serializable]
public class XamlParseException : Exception
{
readonly string _unformattedMessage;
/// <include file="../../docs/Microsoft.Maui.Controls.Xaml/XamlParseException.xml" path="//Member[@MemberName='.ctor'][1]/Docs/*" />
public XamlParseException()
{
}
/// <include file="../../docs/Microsoft.Maui.Controls.Xaml/XamlParseException.xml" path="//Member[@MemberName='.ctor'][2]/Docs/*" />
public XamlParseException(string message)
: base(message)
{
}
/// <include file="../../docs/Microsoft.Maui.Controls.Xaml/XamlParseException.xml" path="//Member[@MemberName='.ctor'][4]/Docs/*" />
public XamlParseException(string message, Exception innerException)
: base(message, innerException)
{
}
/// <include file="../../docs/Microsoft.Maui.Controls.Xaml/XamlParseException.xml" path="//Member[@MemberName='.ctor'][3]/Docs/*" />
#if !NETSTANDARD
[ObsoleteAttribute("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
protected XamlParseException(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
internal XamlParseException(string message, IServiceProvider serviceProvider, Exception innerException = null)
: this(message, GetLineInfo(serviceProvider), innerException)
{
}
/// <include file="../../docs/Microsoft.Maui.Controls.Xaml/XamlParseException.xml" path="//Member[@MemberName='.ctor'][5]/Docs/*" />
public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null)
: base(FormatMessage(message, xmlInfo), innerException)
{
_unformattedMessage = message;
XmlInfo = xmlInfo;
}
/// <include file="../../docs/Microsoft.Maui.Controls.Xaml/XamlParseException.xml" path="//Member[@MemberName='XmlInfo']/Docs/*" />
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();
}
}