Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Xml / System / Xml / Xslt / XsltException.cs
blobd724bcb10d4e7d4a6bc83047834b726ae20aa795
1 //------------------------------------------------------------------------------
2 // <copyright file="XsltException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System.Globalization;
9 using System.Resources;
10 using System.Runtime.Serialization;
11 using System.Security.Permissions;
12 using System.Xml.XPath;
14 namespace System.Xml.Xsl {
15 using Res = System.Xml.Utils.Res;
17 [Serializable]
18 public class XsltException : SystemException {
19 string res;
20 string[] args;
21 string sourceUri;
22 int lineNumber;
23 int linePosition;
25 // message != null for V1 & V2 exceptions deserialized in Whidbey
26 // message == null for created V2 exceptions; the exception message is stored in Exception._message
27 string message;
29 protected XsltException(SerializationInfo info, StreamingContext context) : base(info, context) {
30 res = (string) info.GetValue("res" , typeof(string ));
31 args = (string[]) info.GetValue("args" , typeof(string[] ));
32 sourceUri = (string) info.GetValue("sourceUri" , typeof(string ));
33 lineNumber = (int) info.GetValue("lineNumber" , typeof(int ));
34 linePosition = (int) info.GetValue("linePosition", typeof(int ));
36 // deserialize optional members
37 string version = null;
38 foreach ( SerializationEntry e in info ) {
39 if ( e.Name == "version" ) {
40 version = (string)e.Value;
44 if (version == null) {
45 // deserializing V1 exception
46 message = CreateMessage(res, args, sourceUri, lineNumber, linePosition);
48 else {
49 // deserializing V2 or higher exception -> exception message is serialized by the base class (Exception._message)
50 message = null;
54 [SecurityPermissionAttribute(SecurityAction.LinkDemand,SerializationFormatter=true)]
55 public override void GetObjectData(SerializationInfo info, StreamingContext context) {
56 base.GetObjectData(info, context);
57 info.AddValue("res" , res );
58 info.AddValue("args" , args );
59 info.AddValue("sourceUri" , sourceUri );
60 info.AddValue("lineNumber" , lineNumber );
61 info.AddValue("linePosition", linePosition);
62 info.AddValue("version" , "2.0");
65 public XsltException() : this (string.Empty, (Exception) null) {}
67 public XsltException(String message) : this (message, (Exception) null) {}
69 public XsltException(String message, Exception innerException) :
70 this(Res.Xml_UserException, new string[] { message }, null, 0, 0, innerException ) {
73 internal static XsltException Create(string res, params string[] args) {
74 return new XsltException(res, args, null, 0, 0, null);
77 internal static XsltException Create(string res, string[] args, Exception inner) {
78 return new XsltException(res, args, null, 0, 0, inner);
81 internal XsltException(string res, string[] args, string sourceUri, int lineNumber, int linePosition, Exception inner)
82 : base(CreateMessage(res, args, sourceUri, lineNumber, linePosition), inner)
84 HResult = HResults.XmlXslt;
85 this.res = res;
86 this.sourceUri = sourceUri;
87 this.lineNumber = lineNumber;
88 this.linePosition = linePosition;
91 public virtual string SourceUri {
92 get { return this.sourceUri; }
95 public virtual int LineNumber {
96 get { return this.lineNumber; }
99 public virtual int LinePosition {
100 get { return this.linePosition; }
103 public override string Message {
104 get {
105 return (message == null) ? base.Message : message;
109 private static string CreateMessage(string res, string[] args, string sourceUri, int lineNumber, int linePosition) {
110 try {
111 string message = FormatMessage(res, args);
112 if (res != Res.Xslt_CompileError && lineNumber != 0) {
113 message += " " + FormatMessage(Res.Xml_ErrorFilePosition, sourceUri, lineNumber.ToString(CultureInfo.InvariantCulture), linePosition.ToString(CultureInfo.InvariantCulture));
115 return message;
117 catch (MissingManifestResourceException) {
118 return "UNKNOWN(" + res + ")";
122 private static string FormatMessage(string key, params string[] args) {
123 string message = Res.GetString(key);
124 if (message != null && args != null) {
125 message = string.Format(CultureInfo.InvariantCulture, message, args);
127 return message;
131 [Serializable]
132 public class XsltCompileException : XsltException {
134 protected XsltCompileException(SerializationInfo info, StreamingContext context) : base(info, context) {}
136 [SecurityPermissionAttribute(SecurityAction.LinkDemand,SerializationFormatter=true)]
137 public override void GetObjectData(SerializationInfo info, StreamingContext context) {
138 base.GetObjectData(info, context);
141 public XsltCompileException() : base() {}
143 public XsltCompileException(String message) : base (message) {}
145 public XsltCompileException(String message, Exception innerException) : base (message, innerException) {}
147 public XsltCompileException(Exception inner, string sourceUri, int lineNumber, int linePosition) :
148 base(
149 lineNumber != 0 ? Res.Xslt_CompileError : Res.Xslt_CompileError2,
150 new string[] { sourceUri, lineNumber.ToString(CultureInfo.InvariantCulture), linePosition.ToString(CultureInfo.InvariantCulture) },
151 sourceUri, lineNumber, linePosition, inner
152 ) {}