Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Create()

static IdDictionary ReLogic.Reflection.IdDictionary.Create ( Type idClass,
Type idType )
inlinestatic

Definition at line 71 of file IdDictionary.cs.

72 {
73 int num = int.MaxValue;
74 FieldInfo fieldInfo = idClass.GetFields().FirstOrDefault((FieldInfo field) => field.Name == "Count");
75 if (fieldInfo != null)
76 {
77 num = Convert.ToInt32(fieldInfo.GetValue(null));
78 if (num == 0)
79 {
80 throw new Exception("IdDictionary cannot be created before Count field is initialized. Move to bottom of static class");
81 }
82 }
84 (from f in idClass.GetFields(BindingFlags.Static | BindingFlags.Public)
85 where f.FieldType == idType
86 where f.GetCustomAttribute<ObsoleteAttribute>() == null
87 select f).ToList().ForEach(delegate(FieldInfo field)
88 {
89 int num2 = Convert.ToInt32(field.GetValue(null));
90 if (num2 < dictionary.Count)
91 {
92 dictionary._nameToId.Add(field.Name, num2);
93 }
94 });
95 dictionary._idToName = dictionary._nameToId.ToDictionary((KeyValuePair<string, int> kp) => kp.Value, (KeyValuePair<string, int> kp) => kp.Key);
96 return dictionary;
97 }
static int ToInt32(object? value)
Definition Convert.cs:1320

References ReLogic.Reflection.IdDictionary.IdDictionary(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.dictionary, and System.Convert.ToInt32().

Referenced by ReLogic.Reflection.IdDictionary.Create< IdClass, IdType >().