Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FieldNameLookup.cs
Go to the documentation of this file.
4
6
7internal sealed class FieldNameLookup
8{
10
11 private readonly string[] _fieldNames;
12
14
15 private readonly int _defaultLocaleID;
16
17 public FieldNameLookup(IDataRecord reader, int defaultLocaleID)
18 {
19 int fieldCount = reader.FieldCount;
20 string[] array = new string[fieldCount];
21 for (int i = 0; i < fieldCount; i++)
22 {
23 array[i] = reader.GetName(i);
24 }
26 _defaultLocaleID = defaultLocaleID;
27 }
28
29 public int GetOrdinal(string fieldName)
30 {
31 if (fieldName == null)
32 {
33 throw ADP.ArgumentNull("fieldName");
34 }
35 int num = IndexOf(fieldName);
36 if (-1 == num)
37 {
38 throw ADP.IndexOutOfRange(fieldName);
39 }
40 return num;
41 }
42
43 public int IndexOf(string fieldName)
44 {
45 if (_fieldNameLookup == null)
46 {
48 }
49 object obj = _fieldNameLookup[fieldName];
50 int num;
51 if (obj != null)
52 {
53 num = (int)obj;
54 }
55 else
56 {
57 num = LinearIndexOf(fieldName, CompareOptions.IgnoreCase);
58 if (-1 == num)
59 {
60 num = LinearIndexOf(fieldName, CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth);
61 }
62 }
63 return num;
64 }
65
66 private int LinearIndexOf(string fieldName, CompareOptions compareOptions)
67 {
68 CompareInfo compareInfo = _compareInfo;
69 if (compareInfo == null)
70 {
71 if (-1 != _defaultLocaleID)
72 {
74 }
75 if (compareInfo == null)
76 {
77 compareInfo = CultureInfo.InvariantCulture.CompareInfo;
78 }
79 _compareInfo = compareInfo;
80 }
81 int num = _fieldNames.Length;
82 for (int i = 0; i < num; i++)
83 {
84 if (compareInfo.Compare(fieldName, _fieldNames[i], compareOptions) == 0)
85 {
86 _fieldNameLookup[fieldName] = i;
87 return i;
88 }
89 }
90 return -1;
91 }
92
93 private void GenerateLookup()
94 {
95 int num = _fieldNames.Length;
96 Hashtable hashtable = new Hashtable(num);
97 int num2 = num - 1;
98 while (0 <= num2)
99 {
100 string key = _fieldNames[num2];
101 hashtable[key] = num2;
102 num2--;
103 }
104 _fieldNameLookup = hashtable;
105 }
106}
static ArgumentNullException ArgumentNull(string parameter)
Definition ADP.cs:699
static IndexOutOfRangeException IndexOutOfRange(string error)
Definition ADP.cs:727
FieldNameLookup(IDataRecord reader, int defaultLocaleID)
int LinearIndexOf(string fieldName, CompareOptions compareOptions)
int Compare(string? string1, string? string2)
static CompareInfo GetCompareInfo(int culture, Assembly assembly)
static CultureInfo InvariantCulture
string GetName(int i)