Terraria ModLoader  0.11.1
A framework for Terraria mods
Terraria.ModLoader.IO.TagCompound Class Reference
+ Inheritance diagram for Terraria.ModLoader.IO.TagCompound:
+ Collaboration diagram for Terraria.ModLoader.IO.TagCompound:

Public Member Functions

void Add (string key, object value)
 
void Add (KeyValuePair< string, object > entry)
 
void Clear ()
 
object Clone ()
 
bool ContainsKey (string key)
 
Get< T > (string key)
 
double GetAsDouble (string key)
 
int GetAsInt (string key)
 
long GetAsLong (string key)
 
short GetAsShort (string key)
 
bool GetBool (string key)
 
byte GetByte (string key)
 
byte [] GetByteArray (string key)
 
TagCompound GetCompound (string key)
 
double GetDouble (string key)
 
IEnumerator< KeyValuePair< string, object > > GetEnumerator ()
 
float GetFloat (string key)
 
int GetInt (string key)
 
int [] GetIntArray (string key)
 
IList< T > GetList< T > (string key)
 
long GetLong (string key)
 
short GetShort (string key)
 
string GetString (string key)
 
GetTag< T > (string key)
 
bool HasTag (string key)
 
bool Remove (string key)
 
bool RemoveTag (string key)
 
void Set (string key, object value)
 
void Set (string key, object value, bool replace=false)
 
void SetTag (string key, object value)
 
override string ToString ()
 

Public Attributes

int Count => dict.Count
 

Properties

object this[string key] [get, set]
 

Private Member Functions

IEnumerator IEnumerable. GetEnumerator ()
 

Private Attributes

Dictionary< string, object > dict = new Dictionary<string, object>()
 

Detailed Description

Definition at line 14 of file TagCompound.cs.

Member Function Documentation

◆ Add() [1/2]

void Terraria.ModLoader.IO.TagCompound.Add ( string  key,
object  value 
)

◆ Add() [2/2]

void Terraria.ModLoader.IO.TagCompound.Add ( KeyValuePair< string, object >  entry)

◆ Clear()

void Terraria.ModLoader.IO.TagCompound.Clear ( )

Definition at line 121 of file TagCompound.cs.

121 { dict.Clear(); }
Dictionary< string, object > dict
Definition: TagCompound.cs:16

◆ Clone()

object Terraria.ModLoader.IO.TagCompound.Clone ( )

Definition at line 99 of file TagCompound.cs.

99  {
100  var copy = new TagCompound();
101  foreach (var entry in this)
102  copy.Set(entry.Key, TagIO.Clone(entry.Value));
103 
104  return copy;
105  }

◆ ContainsKey()

bool Terraria.ModLoader.IO.TagCompound.ContainsKey ( string  key)

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

◆ Get< T >()

T Terraria.ModLoader.IO.TagCompound.Get< T > ( string  key)

Definition at line 17 of file TagCompound.cs.

References Terraria.ModLoader.IO.TagIO.Deserialize().

17  {
18  object tag = null;
19  dict.TryGetValue(key, out tag);
20  try {
21  return TagIO.Deserialize<T>(tag);
22  }
23  catch (Exception e) {
24  throw new IOException(
25  $"NBT Deserialization (type={typeof(T)}," +
26  $"entry={TagPrinter.Print(new KeyValuePair<string, object>(key, tag))})", e);
27  }
28  }
Dictionary< string, object > dict
Definition: TagCompound.cs:16
+ Here is the call graph for this function:

◆ GetAsDouble()

double Terraria.ModLoader.IO.TagCompound.GetAsDouble ( string  key)

Definition at line 94 of file TagCompound.cs.

94  {
95  var o = Get<object>(key);
96  return o as double? ?? o as float? ?? 0;
97  }

◆ GetAsInt()

int Terraria.ModLoader.IO.TagCompound.GetAsInt ( string  key)

Definition at line 84 of file TagCompound.cs.

84  {
85  var o = Get<object>(key);
86  return o as int? ?? o as short? ?? o as byte? ?? 0;
87  }

◆ GetAsLong()

long Terraria.ModLoader.IO.TagCompound.GetAsLong ( string  key)

Definition at line 89 of file TagCompound.cs.

89  {
90  var o = Get<object>(key);
91  return o as long? ?? o as int? ?? o as short? ?? o as byte? ?? 0;
92  }

◆ GetAsShort()

short Terraria.ModLoader.IO.TagCompound.GetAsShort ( string  key)

Definition at line 79 of file TagCompound.cs.

79  {
80  var o = Get<object>(key);
81  return o as short? ?? o as byte? ?? 0;
82  }

◆ GetBool()

bool Terraria.ModLoader.IO.TagCompound.GetBool ( string  key)

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

◆ GetByte()

byte Terraria.ModLoader.IO.TagCompound.GetByte ( string  key)

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

◆ GetByteArray()

byte [] Terraria.ModLoader.IO.TagCompound.GetByteArray ( string  key)

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

◆ GetCompound()

TagCompound Terraria.ModLoader.IO.TagCompound.GetCompound ( string  key)

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

◆ GetDouble()

double Terraria.ModLoader.IO.TagCompound.GetDouble ( string  key)

◆ GetEnumerator() [1/2]

IEnumerator<KeyValuePair<string, object> > Terraria.ModLoader.IO.TagCompound.GetEnumerator ( )

◆ GetEnumerator() [2/2]

IEnumerator IEnumerable. Terraria.ModLoader.IO.TagCompound.GetEnumerator ( )
private

◆ GetFloat()

float Terraria.ModLoader.IO.TagCompound.GetFloat ( string  key)

◆ GetInt()

int Terraria.ModLoader.IO.TagCompound.GetInt ( string  key)

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

◆ GetIntArray()

int [] Terraria.ModLoader.IO.TagCompound.GetIntArray ( string  key)

◆ GetList< T >()

IList<T> Terraria.ModLoader.IO.TagCompound.GetList< T > ( string  key)

◆ GetLong()

long Terraria.ModLoader.IO.TagCompound.GetLong ( string  key)

◆ GetShort()

short Terraria.ModLoader.IO.TagCompound.GetShort ( string  key)

◆ GetString()

string Terraria.ModLoader.IO.TagCompound.GetString ( string  key)

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

◆ GetTag< T >()

T Terraria.ModLoader.IO.TagCompound.GetTag< T > ( string  key)

◆ HasTag()

bool Terraria.ModLoader.IO.TagCompound.HasTag ( string  key)

◆ Remove()

bool Terraria.ModLoader.IO.TagCompound.Remove ( string  key)

◆ RemoveTag()

bool Terraria.ModLoader.IO.TagCompound.RemoveTag ( string  key)

◆ Set() [1/2]

void Terraria.ModLoader.IO.TagCompound.Set ( string  key,
object  value 
)

◆ Set() [2/2]

void Terraria.ModLoader.IO.TagCompound.Set ( string  key,
object  value,
bool  replace = false 
)

Definition at line 34 of file TagCompound.cs.

References Terraria.ModLoader.IO.TagIO.Serialize().

34  {
35  if (value == null) {
36  Remove(key);
37  return;
38  }
39 
40  object serialized;
41  try {
42  serialized = TagIO.Serialize(value);
43  }
44  catch (IOException e) {
45  var valueInfo = "value=" + value;
46  if (value.GetType().ToString() != value.ToString())
47  valueInfo = "type=" + value.GetType() + "," + valueInfo;
48  throw new IOException($"NBT Serialization (key={key},{valueInfo})", e);
49  }
50  if (replace)
51  dict[key] = serialized;
52  else
53  dict.Add(key, serialized);
54  }
Dictionary< string, object > dict
Definition: TagCompound.cs:16
+ Here is the call graph for this function:

◆ SetTag()

void Terraria.ModLoader.IO.TagCompound.SetTag ( string  key,
object  value 
)

◆ ToString()

override string Terraria.ModLoader.IO.TagCompound.ToString ( )

Definition at line 107 of file TagCompound.cs.

References Terraria.ModLoader.IO.TagPrinter.Print().

107  {
108  return TagPrinter.Print(this);
109  }
+ Here is the call graph for this function:

Member Data Documentation

◆ Count

int Terraria.ModLoader.IO.TagCompound.Count => dict.Count

Definition at line 122 of file TagCompound.cs.

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

◆ dict

Dictionary<string, object> Terraria.ModLoader.IO.TagCompound.dict = new Dictionary<string, object>()
private

Definition at line 16 of file TagCompound.cs.

Property Documentation

◆ this[string key]

object Terraria.ModLoader.IO.TagCompound.this[string key]
getset

Definition at line 111 of file TagCompound.cs.