tModLoader v0.11.8.9
A mod to make and play Terraria mods
Terraria.ModLoader.IO.TagPrinter Class Reference
+ Collaboration diagram for Terraria.ModLoader.IO.TagPrinter:

Public Member Functions

override string ToString ()
 

Static Public Member Functions

static string Print (KeyValuePair< string, object > entry)
 
static string Print (TagCompound tag)
 

Private Member Functions

string TypeString (Type type)
 
void WriteEntry (KeyValuePair< string, object > entry)
 
void WriteList< T > (char start, char end, bool multiline, IEnumerable< T > list, Action< T > write)
 
void WriteValue (object elem)
 

Private Attributes

string indent = ""
 
StringBuilder sb = new StringBuilder()
 

Detailed Description

Definition at line 9 of file TagPrinter.cs.

Member Function Documentation

◆ Print() [1/2]

static string Terraria.ModLoader.IO.TagPrinter.Print ( KeyValuePair< string, object >  entry)
static

Definition at line 110 of file TagPrinter.cs.

110 {
111 var printer = new TagPrinter();
112 printer.WriteEntry(entry);
113 return printer.ToString();
114 }

◆ Print() [2/2]

static string Terraria.ModLoader.IO.TagPrinter.Print ( TagCompound  tag)
static

Definition at line 104 of file TagPrinter.cs.

104 {
105 var printer = new TagPrinter();
106 printer.WriteValue(tag);
107 return printer.ToString();
108 }

Referenced by Terraria.ModLoader.IO.TagCompound.ToString().

+ Here is the caller graph for this function:

◆ ToString()

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

Definition at line 14 of file TagPrinter.cs.

14 {
15 return sb.ToString();
16 }

References Terraria.ModLoader.IO.TagPrinter.sb.

◆ TypeString()

string Terraria.ModLoader.IO.TagPrinter.TypeString ( Type  type)
private

Definition at line 18 of file TagPrinter.cs.

18 {
19 if (type == typeof(byte)) return "byte";
20 if (type == typeof(short)) return "short";
21 if (type == typeof(int)) return "int";
22 if (type == typeof(long)) return "long";
23 if (type == typeof(float)) return "float";
24 if (type == typeof(double)) return "double";
25 if (type == typeof(string)) return "string";
26 if (type == typeof(byte[])) return "byte[]";
27 if (type == typeof(int[])) return "int[]";
28 if (type == typeof(TagCompound)) return "object";
29 if (type == typeof(IList)) return "list";
30 throw new ArgumentException("Unknown Type: " + type);
31 }

Referenced by Terraria.ModLoader.IO.TagPrinter.WriteEntry(), and Terraria.ModLoader.IO.TagPrinter.WriteValue().

+ Here is the caller graph for this function:

◆ WriteEntry()

void Terraria.ModLoader.IO.TagPrinter.WriteEntry ( KeyValuePair< string, object >  entry)
private

Definition at line 49 of file TagPrinter.cs.

49 {
50 if (entry.Value == null) {
51 sb.Append('"').Append(entry.Key).Append("\" = null");
52 return;
53 }
54
55 var type = entry.Value.GetType();
56 var isList = entry.Value is IList && !(entry.Value is Array);
57 sb.Append(TypeString(isList ? type.GetGenericArguments()[0] : type));
58
59 sb.Append(" \"").Append(entry.Key).Append("\" ");
60
61 if (type != typeof(TagCompound) && !isList)
62 sb.Append("= ");
63
64 WriteValue(entry.Value);
65 }
string TypeString(Type type)
Definition: TagPrinter.cs:18
void WriteValue(object elem)
Definition: TagPrinter.cs:67

References Terraria.ModLoader.IO.TagPrinter.sb, Terraria.ModLoader.IO.TagPrinter.TypeString(), and Terraria.ModLoader.IO.TagPrinter.WriteValue().

Referenced by Terraria.ModLoader.IO.TagPrinter.WriteValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteList< T >()

void Terraria.ModLoader.IO.TagPrinter.WriteList< T > ( char  start,
char  end,
bool  multiline,
IEnumerable< T >  list,
Action< T >  write 
)
private

Definition at line 33 of file TagPrinter.cs.

33 {
34 sb.Append(start);
35 indent += " ";
36 var first = true;
37 foreach (var entry in list) {
38 if (first) first = false;
39 else sb.Append(multiline ? "," : ", ");
40
41 if (multiline) sb.AppendLine().Append(indent);
42 write(entry);
43 }
44 indent = indent.Substring(2);
45 if (multiline && !first) sb.AppendLine().Append(indent);
46 sb.Append(end);
47 }

References Terraria.ModLoader.IO.TagPrinter.indent, and Terraria.ModLoader.IO.TagPrinter.sb.

◆ WriteValue()

void Terraria.ModLoader.IO.TagPrinter.WriteValue ( object  elem)
private

Definition at line 67 of file TagPrinter.cs.

67 {
68 if (elem is byte)
69 sb.Append((byte)elem);
70 else if (elem is short)
71 sb.Append((short)elem);
72 else if (elem is int)
73 sb.Append((int)elem);
74 else if (elem is long)
75 sb.Append((long)elem);
76 else if (elem is float)
77 sb.Append((float)elem);
78 else if (elem is double)
79 sb.Append((double)elem);
80 else if (elem is string)
81 sb.Append('"').Append((string)elem).Append('"');
82 else if (elem is byte[])
83 sb.Append('[').Append(string.Join(", ", (byte[])elem)).Append(']');
84 else if (elem is int[])
85 sb.Append('[').Append(string.Join(", ", (int[])elem)).Append(']');
86 else if (elem is TagCompound) {
87 var tag = (TagCompound)elem;
88 WriteList('{', '}', true, tag, WriteEntry);
89 }
90 else if (elem is IList) {
91 var type = elem.GetType().GetGenericArguments()[0];
92 WriteList('[', ']',
93 type == typeof(string) || type == typeof(TagCompound) || typeof(IList).IsAssignableFrom(type),
94 ((IList)elem).Cast<object>(),
95 o => {
96 if (type == typeof(IList)) //lists of lists need their subtype printed
97 sb.Append(TypeString(o.GetType().GetGenericArguments()[0])).Append(' ');
98
99 WriteValue(o);
100 });
101 }
102 }
void WriteEntry(KeyValuePair< string, object > entry)
Definition: TagPrinter.cs:49

References Terraria.ModLoader.IO.TagPrinter.sb, Terraria.ModLoader.IO.TagPrinter.TypeString(), Terraria.ModLoader.IO.TagPrinter.WriteEntry(), and Terraria.ModLoader.IO.TagPrinter.WriteValue().

Referenced by Terraria.ModLoader.IO.TagPrinter.WriteEntry(), and Terraria.ModLoader.IO.TagPrinter.WriteValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ indent

string Terraria.ModLoader.IO.TagPrinter.indent = ""
private

Definition at line 11 of file TagPrinter.cs.

Referenced by Terraria.ModLoader.IO.TagPrinter.WriteList< T >().

◆ sb

StringBuilder Terraria.ModLoader.IO.TagPrinter.sb = new StringBuilder()
private