Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ChatCommandId.cs
Go to the documentation of this file.
1using System.IO;
2using System.Text;
5
6namespace Terraria.Chat;
7
8public struct ChatCommandId
9{
10 private readonly string _name;
11
12 private ChatCommandId(string name)
13 {
14 _name = name;
15 }
16
17 public static ChatCommandId FromType<T>() where T : IChatCommand
18 {
19 ChatCommandAttribute cacheableAttribute = AttributeUtilities.GetCacheableAttribute<T, ChatCommandAttribute>();
20 if (cacheableAttribute != null)
21 {
22 return new ChatCommandId(cacheableAttribute.Name);
23 }
24 return new ChatCommandId(null);
25 }
26
27 public void Serialize(BinaryWriter writer)
28 {
29 writer.Write(_name ?? "");
30 }
31
33 {
34 return new ChatCommandId(reader.ReadString());
35 }
36
38 {
39 return 4 + Encoding.UTF8.GetByteCount(_name ?? "");
40 }
41}
virtual string ReadString()
static Encoding UTF8
Definition Encoding.cs:526
void Serialize(BinaryWriter writer)
static ChatCommandId Deserialize(BinaryReader reader)
static ChatCommandId FromType< T >()