Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlQueryContext.cs
Go to the documentation of this file.
5using System.IO;
9
11
13public sealed class XmlQueryContext
14{
15 private readonly XmlQueryRuntime _runtime;
16
18
19 private readonly XmlResolver _dataSources;
20
21 private readonly Hashtable _dataSourceCache;
22
23 private readonly XsltArgumentList _argList;
24
26
28
30
32
34 {
35 get
36 {
37 if (_defaultDataSource == null)
38 {
39 return null;
40 }
42 }
43 }
44
46 {
47 get
48 {
49 if (_defaultDataSource == null)
50 {
52 }
53 return _defaultDataSource;
54 }
55 }
56
85
87 {
89 try
90 {
91 Uri baseUri = ((uriBase != null) ? _dataSources.ResolveUri(null, uriBase) : null);
92 Uri uri = _dataSources.ResolveUri(baseUri, uriRelative);
93 if (uri != null)
94 {
96 }
97 if (xPathNavigator == null)
98 {
99 object entity = _dataSources.GetEntity(uri, null, null);
100 if (entity != null)
101 {
104 }
105 }
106 }
108 {
109 throw;
110 }
111 catch (Exception ex2)
112 {
114 {
115 throw;
116 }
118 }
119 return xPathNavigator;
120 }
121
123 {
125 {
127 try
128 {
130 }
131 finally
132 {
133 xmlReader.Close();
134 }
135 }
137 {
139 }
141 {
142 if (_wsRules != null)
143 {
144 throw new XslTransformException(System.SR.XmlIl_CantStripNav, string.Empty);
145 }
146 return (dataSource as IXPathNavigable).CreateNavigator();
147 }
149 }
150
151 public object GetParameter(string localName, string namespaceUri)
152 {
153 if (_argList == null)
154 {
155 return null;
156 }
157 return _argList.GetParam(localName, namespaceUri);
158 }
159
160 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "In order for this code path to be hit, a previous call to XsltArgumentList.AddExtensionObject is required. That method is already annotated as unsafe and throwing a warning, so we can suppress here.")]
161 public object GetLateBoundObject(string namespaceUri)
162 {
163 if (_argList == null)
164 {
165 return null;
166 }
167 return _argList.GetExtensionObject(namespaceUri);
168 }
169
170 [RequiresUnreferencedCode("The extension function referenced will be called from the stylesheet which cannot be statically analyzed.")]
171 public bool LateBoundFunctionExists(string name, string namespaceUri)
172 {
173 if (_argList == null)
174 {
175 return false;
176 }
177 object extensionObject = _argList.GetExtensionObject(namespaceUri);
178 if (extensionObject == null)
179 {
180 return false;
181 }
182 return new XmlExtensionFunction(name, namespaceUri, -1, extensionObject.GetType(), BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public).CanBind();
183 }
184
185 [RequiresUnreferencedCode("The extension function referenced will be called from the stylesheet which cannot be statically analyzed.")]
186 public IList<XPathItem> InvokeXsltLateBoundFunction(string name, string namespaceUri, IList<XPathItem>[] args)
187 {
188 object obj = ((_argList != null) ? _argList.GetExtensionObject(namespaceUri) : null);
189 if (obj == null)
190 {
191 throw new XslTransformException(System.SR.XmlIl_UnknownExtObj, namespaceUri);
192 }
193 if (_extFuncsLate == null)
194 {
196 }
197 XmlExtensionFunction xmlExtensionFunction = _extFuncsLate.Bind(name, namespaceUri, args.Length, obj.GetType(), BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
198 object[] array = new object[args.Length];
199 for (int i = 0; i < args.Length; i++)
200 {
201 XmlQueryType xmlArgumentType = xmlExtensionFunction.GetXmlArgumentType(i);
202 switch (xmlArgumentType.TypeCode)
203 {
204 case XmlTypeCode.Boolean:
206 break;
207 case XmlTypeCode.Double:
209 break;
210 case XmlTypeCode.String:
212 break;
213 case XmlTypeCode.Node:
214 if (xmlArgumentType.IsSingleton)
215 {
216 array[i] = XsltConvert.ToNode(args[i]);
217 }
218 else
219 {
221 }
222 break;
223 case XmlTypeCode.Item:
224 array[i] = args[i];
225 break;
226 }
227 Type clrArgumentType = xmlExtensionFunction.GetClrArgumentType(i);
228 if (xmlArgumentType.TypeCode == XmlTypeCode.Item || !clrArgumentType.IsAssignableFrom(array[i].GetType()))
229 {
231 }
232 }
233 object obj2 = xmlExtensionFunction.Invoke(obj, array);
234 if (obj2 == null && xmlExtensionFunction.ClrReturnType == XsltConvert.VoidType)
235 {
237 }
239 }
240
241 public void OnXsltMessageEncountered(string message)
242 {
243 ((_argList != null) ? _argList.xsltMessageEncountered : null)?.Invoke(this, new XmlILQueryEventArgs(message));
244 }
245}
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
static string XmlIl_CantStripNav
Definition SR.cs:2048
static string XmlIl_UnknownExtObj
Definition SR.cs:2046
static string XmlIl_UnknownDocument
Definition SR.cs:2042
static string XmlIl_NoDefaultDocument
Definition SR.cs:2040
static string XmlIl_CantResolveEntity
Definition SR.cs:2038
static string XmlIl_DocumentLoadError
Definition SR.cs:2064
Definition SR.cs:7
static bool IsCatchableException(Exception e)
object? GetEntity(Uri absoluteUri, string? role, Type? ofObjectToReturn)
virtual Uri ResolveUri(Uri? baseUri, string? relativeUri)
XmlReader CreateReader(Stream stream, string baseUri)
static XmlReader CreateReader(XmlReader baseReader, WhitespaceRuleLookup wsRules)
XmlExtensionFunction Bind(string name, string namespaceUri, int numArgs, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.NonPublicMethods)] Type objectType, BindingFlags flags)
readonly XPathNavigator _defaultDataSource
XmlQueryContext(XmlQueryRuntime runtime, object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList, WhitespaceRuleLookup wsRules)
XPathNavigator GetDataSource(string uriRelative, string uriBase)
IList< XPathItem > InvokeXsltLateBoundFunction(string name, string namespaceUri, IList< XPathItem >[] args)
readonly WhitespaceRuleLookup _wsRules
bool LateBoundFunctionExists(string name, string namespaceUri)
object GetParameter(string localName, string namespaceUri)
object GetLateBoundObject(string namespaceUri)
readonly QueryReaderSettings _readerSettings
XPathNavigator ConstructDocument(object dataSource, string uriRelative, Uri uriResolved)
XmlExtensionFunctionTable _extFuncsLate
static new readonly XmlQueryNodeSequence Empty
object ChangeTypeXsltResult(int indexType, object value)
object ChangeTypeXsltArgument(int indexType, object value, Type destinationType)
static IList< XPathNavigator > ToNodeSet(XPathItem item)
static bool ToBoolean(XPathItem item)
static XPathNavigator ToNode(XPathItem item)
static readonly Type VoidType
static double ToDouble(string value)
static string ToString(double value)
static readonly XmlQueryType ItemS
object? GetParam(string name, string namespaceUri)
object? GetExtensionObject(string namespaceUri)
XsltMessageEncounteredEventHandler xsltMessageEncountered