Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlXml.cs
Go to the documentation of this file.
2using System.IO;
4using System.Text;
5using System.Xml;
8
10
11[XmlSchemaProvider("GetXsdType")]
12public sealed class SqlXml : INullable, IXmlSerializable
13{
15
20
22 {
24 CloseInput = true
25 };
26
28
30
31 private bool _fNotNull;
32
33 private Stream _stream;
34
35 private bool _firstCreateReader;
36
38 {
39 get
40 {
42 {
43 s_createSqlReaderMethodInfo = typeof(XmlReader).GetMethod("CreateSqlReader", BindingFlags.Static | BindingFlags.NonPublic);
44 }
46 }
47 }
48
49 public bool IsNull => !_fNotNull;
50
51 public string Value
52 {
53 get
54 {
55 if (IsNull)
56 {
57 throw new SqlNullValueException();
58 }
65 if (xmlReader.ReadState == ReadState.Initial)
66 {
67 xmlReader.Read();
68 }
69 while (!xmlReader.EOF)
70 {
71 xmlWriter.WriteNode(xmlReader, defattr: true);
72 }
73 xmlWriter.Flush();
74 return stringWriter.ToString();
75 }
76 }
77
78 public static SqlXml Null => new SqlXml(fNull: true);
79
80 public SqlXml()
81 {
82 SetNull();
83 }
84
85 private SqlXml(bool fNull)
86 {
87 SetNull();
88 }
89
91 {
92 if (value == null)
93 {
94 SetNull();
95 return;
96 }
97 _fNotNull = true;
98 _firstCreateReader = true;
100 }
101
103 {
104 if (value == null)
105 {
106 SetNull();
107 return;
108 }
109 _firstCreateReader = true;
110 _fNotNull = true;
111 _stream = value;
112 }
113
115 {
116 if (IsNull)
117 {
118 throw new SqlNullValueException();
119 }
121 if ((!_firstCreateReader || sqlXmlStreamWrapper.CanSeek) && sqlXmlStreamWrapper.Position != 0L)
122 {
123 sqlXmlStreamWrapper.Seek(0L, SeekOrigin.Begin);
124 }
125 if (_createSqlReaderMethodInfo == null)
126 {
128 }
130 _firstCreateReader = false;
131 return result;
132 }
133
135 {
137 try
138 {
139 return s_sqlReaderDelegate(stream, arg, null);
140 }
141 catch (Exception ex)
142 {
144 {
145 throw;
146 }
147 throw new TargetInvocationException(ex);
148 }
149 }
150
155
156 private void SetNull()
157 {
158 _fNotNull = false;
159 _stream = null;
160 _firstCreateReader = true;
161 }
162
164 {
172 if (reader.ReadState == ReadState.Closed)
173 {
175 }
176 if (reader.ReadState == ReadState.Initial)
177 {
178 reader.Read();
179 }
180 while (!reader.EOF)
181 {
182 xmlWriter.WriteNode(reader, defattr: true);
183 }
184 xmlWriter.Flush();
185 memoryStream.Seek(0L, SeekOrigin.Begin);
186 return memoryStream;
187 }
188
190 {
191 return null;
192 }
193
195 {
196 string attribute = r.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
197 if (attribute != null && XmlConvert.ToBoolean(attribute))
198 {
199 r.ReadInnerXml();
200 SetNull();
201 return;
202 }
203 _fNotNull = true;
204 _firstCreateReader = true;
205 _stream = new MemoryStream();
207 streamWriter.Write(r.ReadInnerXml());
208 streamWriter.Flush();
209 if (_stream.CanSeek)
210 {
211 _stream.Seek(0L, SeekOrigin.Begin);
212 }
213 }
214
216 {
217 if (IsNull)
218 {
219 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
220 }
221 else
222 {
224 if (xmlReader.ReadState == ReadState.Initial)
225 {
226 xmlReader.Read();
227 }
228 while (!xmlReader.EOF)
229 {
230 writer.WriteNode(xmlReader, defattr: true);
231 }
232 }
233 writer.Flush();
234 }
235
237 {
238 return new XmlQualifiedName("anyType", "http://www.w3.org/2001/XMLSchema");
239 }
240}
static bool IsCatchableExceptionType(Exception e)
Definition ADP.cs:790
static MethodInfo s_createSqlReaderMethodInfo
Definition SqlXml.cs:27
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
Definition SqlXml.cs:236
SqlXml(XmlReader? value)
Definition SqlXml.cs:90
static MethodInfo CreateSqlReaderMethodInfo
Definition SqlXml.cs:38
SqlXml(Stream? value)
Definition SqlXml.cs:102
static readonly Func< Stream, XmlReaderSettings, XmlParserContext, XmlReader > s_sqlReaderDelegate
Definition SqlXml.cs:14
static Func< Stream, XmlReaderSettings, XmlParserContext, XmlReader > CreateSqlReaderDelegate()
Definition SqlXml.cs:151
Stream CreateMemoryStreamFromXmlReader(XmlReader reader)
Definition SqlXml.cs:163
static readonly XmlReaderSettings s_defaultXmlReaderSettings
Definition SqlXml.cs:16
static XmlReader CreateSqlXmlReader(Stream stream, bool closeInput=false, bool throwTargetInvocationExceptions=false)
Definition SqlXml.cs:134
MethodInfo _createSqlReaderMethodInfo
Definition SqlXml.cs:29
static readonly XmlReaderSettings s_defaultXmlReaderSettingsCloseInput
Definition SqlXml.cs:21
long Seek(long offset, SeekOrigin origin)
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
static bool ToBoolean(string s)
static XmlWriter Create(string outputFileName)
Definition XmlWriter.cs:468