Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XslCompiledTransform.cs
Go to the documentation of this file.
3using System.IO;
10
11namespace System.Xml.Xsl;
12
13public sealed class XslCompiledTransform
14{
15 private static readonly Version s_version = typeof(XslCompiledTransform).Assembly.GetName().Version;
16
17 private readonly bool _enableDebug;
18
20
22
24
26
28
30 {
31 }
32
37
38 private void Reset()
39 {
40 _compilerErrorColl = null;
41 _outputSettings = null;
42 _qil = null;
43 _command = null;
44 }
45
46 public void Load(XmlReader stylesheet)
47 {
48 Reset();
50 }
51
52 public void Load(XmlReader stylesheet, XsltSettings? settings, XmlResolver? stylesheetResolver)
53 {
54 Reset();
55 LoadInternal(stylesheet, settings, stylesheetResolver);
56 }
57
58 public void Load(IXPathNavigable stylesheet)
59 {
60 Reset();
62 }
63
64 public void Load(IXPathNavigable stylesheet, XsltSettings? settings, XmlResolver? stylesheetResolver)
65 {
66 Reset();
67 LoadInternal(stylesheet, settings, stylesheetResolver);
68 }
69
70 public void Load(string stylesheetUri)
71 {
72 Reset();
73 if (stylesheetUri == null)
74 {
75 throw new ArgumentNullException("stylesheetUri");
76 }
78 }
79
81 {
82 Reset();
83 if (stylesheetUri == null)
84 {
85 throw new ArgumentNullException("stylesheetUri");
86 }
88 }
89
91 {
92 if (stylesheet == null)
93 {
94 throw new ArgumentNullException("stylesheet");
95 }
96 if (settings == null)
97 {
98 settings = XsltSettings.Default;
99 }
100 CompileXsltToQil(stylesheet, settings, stylesheetResolver);
102 if (firstError != null)
103 {
104 throw new XslLoadException(firstError);
105 }
106 if (!settings.CheckOnly)
107 {
108 CompileQilToMsil(settings);
109 }
110 return _compilerErrorColl;
111 }
112
113 [MemberNotNull("_compilerErrorColl")]
114 [MemberNotNull("_qil")]
115 private void CompileXsltToQil(object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
116 {
117 _compilerErrorColl = new Compiler(settings, _enableDebug, null).Compile(stylesheet, stylesheetResolver, out _qil);
118 }
119
121 {
123 {
124 if (!item.IsWarning)
125 {
126 return item;
127 }
128 }
129 return null;
130 }
131
132 private void CompileQilToMsil(XsltSettings settings)
133 {
134 _command = new XmlILGenerator().Generate(_qil, null);
136 _qil = null;
137 }
138
139 [RequiresUnreferencedCode("This method will get fields and types from the assembly of the passed in compiledStylesheet and call their constructors which cannot be statically analyzed")]
141 {
142 Reset();
143 if (compiledStylesheet == null)
144 {
145 throw new ArgumentNullException("compiledStylesheet");
146 }
147 object[] customAttributes = compiledStylesheet.GetCustomAttributes(typeof(GeneratedCodeAttribute), inherit: false);
150 {
152 {
154 }
155 FieldInfo field = compiledStylesheet.GetField("staticData", BindingFlags.Static | BindingFlags.NonPublic);
156 FieldInfo field2 = compiledStylesheet.GetField("ebTypes", BindingFlags.Static | BindingFlags.NonPublic);
157 if (field != null && field2 != null && field.GetValue(null) is byte[] queryData)
158 {
159 MethodInfo method = compiledStylesheet.GetMethod("Execute", BindingFlags.Static | BindingFlags.NonPublic);
160 Type[] earlyBoundTypes = (Type[])field2.GetValue(null);
162 return;
163 }
164 }
165 if (_command == null)
166 {
167 throw new ArgumentException(System.SR.Format(System.SR.Xslt_NotCompiledStylesheet, compiledStylesheet.FullName), "compiledStylesheet");
168 }
169 }
170
171 [RequiresUnreferencedCode("This method will call into constructors of the earlyBoundTypes array which cannot be statically analyzed.")]
173 {
174 Reset();
175 if (executeMethod == null)
176 {
177 throw new ArgumentNullException("executeMethod");
178 }
179 if (queryData == null)
180 {
181 throw new ArgumentNullException("queryData");
182 }
184 Delegate @delegate = ((dynamicMethod != null) ? dynamicMethod.CreateDelegate(typeof(ExecuteDelegate)) : executeMethod.CreateDelegate(typeof(ExecuteDelegate)));
187 }
188
194
200
208
216
222
228
236
244
251
258
267
276
277 public void Transform(string inputUri, string resultsFile)
278 {
279 if (inputUri == null)
280 {
281 throw new ArgumentNullException("inputUri");
282 }
283 if (resultsFile == null)
284 {
285 throw new ArgumentNullException("resultsFile");
286 }
290 xmlWriter.Close();
291 }
292
299
306
307 private static void CheckArguments(object input, object results)
308 {
309 if (input == null)
310 {
311 throw new ArgumentNullException("input");
312 }
313 if (results == null)
314 {
315 throw new ArgumentNullException("results");
316 }
317 }
318
319 private static void CheckArguments(string inputUri, object results)
320 {
321 if (inputUri == null)
322 {
323 throw new ArgumentNullException("inputUri");
324 }
325 if (results == null)
326 {
327 throw new ArgumentNullException("results");
328 }
329 }
330
331 [MemberNotNull("_command")]
332 private void CheckCommand()
333 {
334 if (_command == null)
335 {
337 }
338 }
339
341 {
343 {
344 return new XmlUrlResolver();
345 }
347 }
348}
static string Xslt_IncompatibleCompiledStylesheetVersion
Definition SR.cs:28
static string Xslt_NoStylesheetLoaded
Definition SR.cs:24
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Xslt_NotCompiledStylesheet
Definition SR.cs:26
Definition SR.cs:7
static Version Parse(string input)
Definition Version.cs:310
static readonly XmlNullResolver Singleton
static XmlReader Create(string inputUri)
static XmlWriter Create(string outputFileName)
Definition XmlWriter.cs:468
void Execute(object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
XmlQueryStaticData StaticData
XmlILCommand Generate(QilExpression query, TypeBuilder typeBldr)
void Transform(XmlReader input, XsltArgumentList? arguments, TextWriter results)
void Transform(IXPathNavigable input, XmlWriter results)
CompilerErrorCollection LoadInternal(object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
void Load(IXPathNavigable stylesheet, XsltSettings? settings, XmlResolver? stylesheetResolver)
static void CheckArguments(object input, object results)
void Load(XmlReader stylesheet, XsltSettings? settings, XmlResolver? stylesheetResolver)
void Load(string stylesheetUri, XsltSettings? settings, XmlResolver? stylesheetResolver)
void Load(IXPathNavigable stylesheet)
void Transform(XmlReader input, XmlWriter results)
void Transform(string inputUri, XsltArgumentList? arguments, XmlWriter results)
void CompileXsltToQil(object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
void Transform(XmlReader input, XsltArgumentList? arguments, XmlWriter results)
void Transform(XmlReader input, XsltArgumentList? arguments, XmlWriter results, XmlResolver? documentResolver)
void Transform(string inputUri, string resultsFile)
void CompileQilToMsil(XsltSettings settings)
void Transform(string inputUri, XsltArgumentList? arguments, Stream results)
void Transform(IXPathNavigable input, XsltArgumentList? arguments, Stream results)
static void CheckArguments(string inputUri, object results)
void Transform(IXPathNavigable input, XsltArgumentList? arguments, XmlWriter results, XmlResolver? documentResolver)
void Load(Type compiledStylesheet)
void Transform(IXPathNavigable input, XsltArgumentList? arguments, XmlWriter results)
void Transform(IXPathNavigable input, XsltArgumentList? arguments, TextWriter results)
void Transform(string inputUri, XmlWriter results)
void Load(MethodInfo executeMethod, byte[] queryData, Type[]? earlyBoundTypes)
void Transform(XmlReader input, XsltArgumentList? arguments, Stream results)
void Transform(string inputUri, XsltArgumentList? arguments, TextWriter results)
static XsltSettings Default
CompilerErrorCollection Compile(object stylesheet, XmlResolver xmlResolver, out QilExpression qil)
Definition Compiler.cs:135
delegate void ExecuteDelegate(XmlQueryRuntime runtime)