Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SimpleType.cs
Go to the documentation of this file.
5using System.Xml;
7
8namespace System.Data;
9
10internal sealed class SimpleType : ISerializable
11{
12 private string _baseType;
13
15
17
18 private string _name = string.Empty;
19
20 private int _length = -1;
21
22 private int _minLength = -1;
23
24 private int _maxLength = -1;
25
26 private string _pattern = string.Empty;
27
28 private string _ns = string.Empty;
29
30 private string _maxExclusive = string.Empty;
31
32 private string _maxInclusive = string.Empty;
33
34 private string _minExclusive = string.Empty;
35
36 private string _minInclusive = string.Empty;
37
38 internal string _enumeration = string.Empty;
39
40 internal string BaseType => _baseType;
41
43
44 internal string Name => _name;
45
46 internal string Namespace => _ns;
47
48 internal int Length => _length;
49
50 internal int MaxLength
51 {
52 get
53 {
54 return _maxLength;
55 }
56 set
57 {
59 }
60 }
61
63
65 {
66 get
67 {
68 if (_ns.Length == 0)
69 {
70 return _name;
71 }
72 return _ns + ":" + _name;
73 }
74 }
75
76 internal SimpleType(string baseType)
77 {
79 }
80
82 {
83 _name = node.Name;
84 _ns = ((node.QualifiedName != null) ? node.QualifiedName.Namespace : "");
86 }
87
92
94 {
96 {
98 }
100 {
102 if (node.BaseXmlSchemaType is XmlSchemaSimpleType xmlSchemaSimpleType && xmlSchemaSimpleType.QualifiedName.Namespace != "http://www.w3.org/2001/XMLSchema")
103 {
105 }
106 if (xmlSchemaSimpleTypeRestriction.BaseTypeName.Namespace == "http://www.w3.org/2001/XMLSchema")
107 {
108 _baseType = xmlSchemaSimpleTypeRestriction.BaseTypeName.Name;
109 }
110 else
111 {
112 _baseType = xmlSchemaSimpleTypeRestriction.BaseTypeName.ToString();
113 }
114 if (_baseSimpleType != null && _baseSimpleType.Name != null && _baseSimpleType.Name.Length > 0)
115 {
117 }
118 else
119 {
121 }
122 if (_baseType == null || _baseType.Length == 0)
123 {
125 _xmlBaseType = null;
126 }
127 if (_baseType == "NOTATION")
128 {
129 _baseType = "string";
130 }
132 {
134 {
135 _length = Convert.ToInt32(facet.Value, null);
136 }
138 {
139 _minLength = Convert.ToInt32(facet.Value, null);
140 }
142 {
143 _maxLength = Convert.ToInt32(facet.Value, null);
144 }
146 {
147 _pattern = facet.Value;
148 }
150 {
151 _enumeration = ((!string.IsNullOrEmpty(_enumeration)) ? (_enumeration + " " + facet.Value) : facet.Value);
152 }
154 {
155 _minExclusive = facet.Value;
156 }
158 {
159 _minInclusive = facet.Value;
160 }
162 {
163 _maxExclusive = facet.Value;
164 }
166 {
167 _maxInclusive = facet.Value;
168 }
169 }
170 }
171 string msdataAttribute = XSDSchema.GetMsdataAttribute(node, "targetNamespace");
172 if (msdataAttribute != null)
173 {
175 }
176 }
177
178 internal bool IsPlainString()
179 {
180 if (XSDSchema.QualifiedName(_baseType) == XSDSchema.QualifiedName("string") && string.IsNullOrEmpty(_name) && _length == -1 && _minLength == -1 && _maxLength == -1 && string.IsNullOrEmpty(_pattern) && string.IsNullOrEmpty(_maxExclusive) && string.IsNullOrEmpty(_maxInclusive) && string.IsNullOrEmpty(_minExclusive) && string.IsNullOrEmpty(_minInclusive))
181 {
182 return string.IsNullOrEmpty(_enumeration);
183 }
184 return false;
185 }
186
187 internal string QualifiedName(string name)
188 {
189 if (!name.Contains(':'))
190 {
191 return "xs:" + name;
192 }
193 return name;
194 }
195
197 {
198 XmlElement xmlElement = dc.CreateElement("xs", "simpleType", "http://www.w3.org/2001/XMLSchema");
199 if (_name != null && _name.Length != 0)
200 {
202 if (inRemoting)
203 {
204 xmlElement.SetAttribute("targetNamespace", "urn:schemas-microsoft-com:xml-msdata", Namespace);
205 }
206 }
207 XmlElement xmlElement2 = dc.CreateElement("xs", "restriction", "http://www.w3.org/2001/XMLSchema");
208 if (!inRemoting)
209 {
210 if (_baseSimpleType != null)
211 {
212 if (_baseSimpleType.Namespace != null && _baseSimpleType.Namespace.Length > 0)
213 {
214 string text = ((prefixes != null) ? ((string)prefixes[_baseSimpleType.Namespace]) : null);
215 if (text != null)
216 {
218 }
219 else
220 {
221 xmlElement2.SetAttribute("base", _baseSimpleType.Name);
222 }
223 }
224 else
225 {
226 xmlElement2.SetAttribute("base", _baseSimpleType.Name);
227 }
228 }
229 else
230 {
231 xmlElement2.SetAttribute("base", QualifiedName(_baseType));
232 }
233 }
234 else
235 {
236 xmlElement2.SetAttribute("base", (_baseSimpleType != null) ? _baseSimpleType.Name : QualifiedName(_baseType));
237 }
238 if (_length >= 0)
239 {
240 XmlElement xmlElement3 = dc.CreateElement("xs", "length", "http://www.w3.org/2001/XMLSchema");
242 xmlElement2.AppendChild(xmlElement3);
243 }
244 if (_maxLength >= 0)
245 {
246 XmlElement xmlElement3 = dc.CreateElement("xs", "maxLength", "http://www.w3.org/2001/XMLSchema");
248 xmlElement2.AppendChild(xmlElement3);
249 }
250 xmlElement.AppendChild(xmlElement2);
251 return xmlElement;
252 }
253
254 internal static SimpleType CreateEnumeratedType(string values)
255 {
256 SimpleType simpleType = new SimpleType("string");
258 return simpleType;
259 }
260
261 internal static SimpleType CreateByteArrayType(string encoding)
262 {
263 return new SimpleType("base64Binary");
264 }
265
267 {
268 SimpleType simpleType = new SimpleType("string");
270 return simpleType;
271 }
272
274 {
275 if (typeCode == StorageType.Char && type == typeof(char))
276 {
277 return new SimpleType("string")
278 {
279 _length = 1
280 };
281 }
282 return null;
283 }
284
286 {
287 if (otherSimpleType == null)
288 {
289 return "otherSimpleType";
290 }
291 if (MaxLength != otherSimpleType.MaxLength)
292 {
293 return "MaxLength";
294 }
295 if (!string.Equals(BaseType, otherSimpleType.BaseType, StringComparison.Ordinal))
296 {
297 return "BaseType";
298 }
299 if (BaseSimpleType != null && otherSimpleType.BaseSimpleType != null && BaseSimpleType.HasConflictingDefinition(otherSimpleType.BaseSimpleType).Length != 0)
300 {
301 return "BaseSimpleType";
302 }
303 return string.Empty;
304 }
305
306 internal bool CanHaveMaxLength()
307 {
308 SimpleType simpleType = this;
309 while (simpleType.BaseSimpleType != null)
310 {
312 }
313 return string.Equals(simpleType.BaseType, "string", StringComparison.OrdinalIgnoreCase);
314 }
315
317 {
318 _name = null;
319 _ns = string.Empty;
320 SimpleType simpleType = this;
321 while (simpleType._baseSimpleType != null)
322 {
324 }
325 _baseType = simpleType._baseType;
327 _xmlBaseType = simpleType._xmlBaseType;
328 }
329}
static int ToInt32(object? value)
Definition Convert.cs:1320
static Exception SimpleTypeNotSupported()
static SimpleType CreateLimitedStringType(int length)
static SimpleType CreateEnumeratedType(string values)
XmlQualifiedName _xmlBaseType
Definition SimpleType.cs:16
SimpleType(string baseType)
Definition SimpleType.cs:76
XmlNode ToNode(XmlDocument dc, Hashtable prefixes, bool inRemoting)
SimpleType(XmlSchemaSimpleType node)
Definition SimpleType.cs:81
void ConvertToAnnonymousSimpleType()
string QualifiedName(string name)
void LoadTypeValues(XmlSchemaSimpleType node)
Definition SimpleType.cs:93
string HasConflictingDefinition(SimpleType otherSimpleType)
static SimpleType CreateSimpleType(StorageType typeCode, Type type)
XmlQualifiedName XmlBaseType
Definition SimpleType.cs:42
SimpleType BaseSimpleType
Definition SimpleType.cs:62
SimpleType _baseSimpleType
Definition SimpleType.cs:14
static SimpleType CreateByteArrayType(string encoding)
static string GetMsdataAttribute(XmlSchemaAnnotated node, string ln)
Definition XSDSchema.cs:342
static string QualifiedName(string name)
Definition XSDSchema.cs:207
static CultureInfo InvariantCulture
virtual void SetAttribute(string name, string? value)
void GetObjectData(SerializationInfo info, StreamingContext context)