Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ExpandoClass.cs
Go to the documentation of this file.
2
3namespace System.Dynamic;
4
5internal sealed class ExpandoClass
6{
7 private readonly string[] _keys;
8
9 private readonly int _hashCode;
10
12
13 internal static readonly ExpandoClass Empty = new ExpandoClass();
14
15 internal string[] Keys => _keys;
16
17 internal ExpandoClass()
18 {
19 _hashCode = 6551;
20 _keys = Array.Empty<string>();
21 }
22
23 internal ExpandoClass(string[] keys, int hashCode)
24 {
25 _hashCode = hashCode;
26 _keys = keys;
27 }
28
30 {
31 int hashCode = _hashCode ^ newKey.GetHashCode();
32 lock (this)
33 {
35 for (int i = 0; i < transitionList.Count; i++)
36 {
38 {
39 transitionList.RemoveAt(i);
40 i--;
41 }
42 else if (string.Equals(expandoClass._keys[expandoClass._keys.Length - 1], newKey, StringComparison.Ordinal))
43 {
44 return expandoClass;
45 }
46 }
47 string[] array = new string[_keys.Length + 1];
48 Array.Copy(_keys, array, _keys.Length);
49 array[_keys.Length] = newKey;
52 return expandoClass2;
53 }
54 }
55
57 {
58 if (_transitions == null)
59 {
61 }
62 if (!_transitions.TryGetValue(hashCode, out var value))
63 {
64 value = (_transitions[hashCode] = new List<WeakReference>());
65 }
66 return value;
67 }
68
69 internal int GetValueIndex(string name, bool caseInsensitive, ExpandoObject obj)
70 {
71 if (caseInsensitive)
72 {
74 }
75 return GetValueIndexCaseSensitive(name);
76 }
77
78 internal int GetValueIndexCaseSensitive(string name)
79 {
80 for (int i = 0; i < _keys.Length; i++)
81 {
82 if (string.Equals(_keys[i], name, StringComparison.Ordinal))
83 {
84 return i;
85 }
86 }
87 return -1;
88 }
89
91 {
92 int num = -1;
93 lock (obj.LockObject)
94 {
95 for (int num2 = _keys.Length - 1; num2 >= 0; num2--)
96 {
97 if (string.Equals(_keys[num2], name, StringComparison.OrdinalIgnoreCase) && !obj.IsDeletedMember(num2))
98 {
99 if (num != -1)
100 {
101 return -2;
102 }
103 num = num2;
104 }
105 }
106 return num;
107 }
108 }
109}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
ExpandoClass(string[] keys, int hashCode)
ExpandoClass FindNewClass(string newKey)
Dictionary< int, List< WeakReference > > _transitions
int GetValueIndex(string name, bool caseInsensitive, ExpandoObject obj)
List< WeakReference > GetTransitionList(int hashCode)
readonly string[] _keys
int GetValueIndexCaseInsensitive(string name, ExpandoObject obj)
int GetValueIndexCaseSensitive(string name)