Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlDictionaryString.cs
Go to the documentation of this file.
3using System.Text;
4
5namespace System.Xml;
6
8{
9 private sealed class EmptyStringDictionary : IXmlDictionary
10 {
11 private readonly XmlDictionaryString _empty;
12
14
16 {
17 _empty = new XmlDictionaryString(this, string.Empty, 0);
18 }
19
20 public bool TryLookup(string value, [NotNullWhen(true)] out XmlDictionaryString result)
21 {
22 if (value == null)
23 {
25 }
26 if (value.Length == 0)
27 {
28 result = _empty;
29 return true;
30 }
31 result = null;
32 return false;
33 }
34
35 public bool TryLookup(int key, [NotNullWhen(true)] out XmlDictionaryString result)
36 {
37 if (key == 0)
38 {
39 result = _empty;
40 return true;
41 }
42 result = null;
43 return false;
44 }
45
47 {
48 if (value == null)
49 {
51 }
52 if (value.Dictionary != this)
53 {
54 result = null;
55 return false;
56 }
57 result = value;
58 return true;
59 }
60 }
61
62 internal const int MinKey = 0;
63
64 internal const int MaxKey = 536870911;
65
66 private readonly IXmlDictionary _dictionary;
67
68 private readonly string _value;
69
70 private readonly int _key;
71
72 private byte[] _buffer;
73
75
77
79
80 public int Key => _key;
81
82 public string Value => _value;
83
85 {
86 if (dictionary == null)
87 {
89 }
90 if (value == null)
91 {
93 }
94 if (key < 0 || key > 536870911)
95 {
97 }
99 _value = value;
100 _key = key;
101 }
102
103 [return: NotNullIfNotNull("s")]
104 internal static string GetString(XmlDictionaryString s)
105 {
106 return s?.Value;
107 }
108
109 internal byte[] ToUTF8()
110 {
111 if (_buffer == null)
112 {
113 _buffer = Encoding.UTF8.GetBytes(_value);
114 }
115 return _buffer;
116 }
117
118 public override string ToString()
119 {
120 return _value;
121 }
122}
static string ValueMustBeInRange
Definition SR.cs:326
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
bool TryLookup(int key, [NotNullWhen(true)] out XmlDictionaryString result)
bool TryLookup(string value, [NotNullWhen(true)] out XmlDictionaryString result)
bool TryLookup(XmlDictionaryString value, [NotNullWhen(true)] out XmlDictionaryString result)
readonly IXmlDictionary _dictionary
static string GetString(XmlDictionaryString s)
static readonly EmptyStringDictionary s_emptyStringDictionary
XmlDictionaryString(IXmlDictionary dictionary, string value, int key)