Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Formatter.cs
Go to the documentation of this file.
4using System.IO;
5
7
8[CLSCompliant(false)]
9public abstract class Formatter : IFormatter
10{
12
14
15 public abstract ISurrogateSelector? SurrogateSelector { get; set; }
16
17 public abstract SerializationBinder? Binder { get; set; }
18
19 public abstract StreamingContext Context { get; set; }
20
21 protected Formatter()
22 {
23 m_objectQueue = new Queue();
25 }
26
27 [Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
28 [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
29 public abstract object Deserialize(Stream serializationStream);
30
31 protected virtual object? GetNext(out long objID)
32 {
33 if (m_objectQueue.Count == 0)
34 {
35 objID = 0L;
36 return null;
37 }
38 object obj = m_objectQueue.Dequeue();
40 if (firstTime)
41 {
43 }
44 return obj;
45 }
46
47 protected virtual long Schedule(object? obj)
48 {
49 if (obj == null)
50 {
51 return 0L;
52 }
53 bool firstTime;
55 if (firstTime)
56 {
58 }
59 return id;
60 }
61
62 [Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
63 [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
64 public abstract void Serialize(Stream serializationStream, object graph);
65
66 protected abstract void WriteArray(object obj, string name, Type memberType);
67
68 protected abstract void WriteBoolean(bool val, string name);
69
70 protected abstract void WriteByte(byte val, string name);
71
72 protected abstract void WriteChar(char val, string name);
73
74 protected abstract void WriteDateTime(DateTime val, string name);
75
76 protected abstract void WriteDecimal(decimal val, string name);
77
78 protected abstract void WriteDouble(double val, string name);
79
80 protected abstract void WriteInt16(short val, string name);
81
82 protected abstract void WriteInt32(int val, string name);
83
84 protected abstract void WriteInt64(long val, string name);
85
86 protected abstract void WriteObjectRef(object? obj, string name, Type memberType);
87
88 protected virtual void WriteMember(string memberName, object? data)
89 {
90 if (data == null)
91 {
92 WriteObjectRef(data, memberName, typeof(object));
93 return;
94 }
95 Type type = data.GetType();
96 if (type == typeof(bool))
97 {
99 }
100 else if (type == typeof(char))
101 {
103 }
104 else if (type == typeof(sbyte))
105 {
107 }
108 else if (type == typeof(byte))
109 {
111 }
112 else if (type == typeof(short))
113 {
115 }
116 else if (type == typeof(int))
117 {
119 }
120 else if (type == typeof(long))
121 {
123 }
124 else if (type == typeof(float))
125 {
127 }
128 else if (type == typeof(double))
129 {
131 }
132 else if (type == typeof(DateTime))
133 {
135 }
136 else if (type == typeof(decimal))
137 {
139 }
140 else if (type == typeof(ushort))
141 {
143 }
144 else if (type == typeof(uint))
145 {
147 }
148 else if (type == typeof(ulong))
149 {
151 }
152 else if (type.IsArray)
153 {
154 WriteArray(data, memberName, type);
155 }
156 else if (type.IsValueType)
157 {
159 }
160 else
161 {
163 }
164 }
165
166 [CLSCompliant(false)]
167 protected abstract void WriteSByte(sbyte val, string name);
168
169 protected abstract void WriteSingle(float val, string name);
170
171 protected abstract void WriteTimeSpan(TimeSpan val, string name);
172
173 [CLSCompliant(false)]
174 protected abstract void WriteUInt16(ushort val, string name);
175
176 [CLSCompliant(false)]
177 protected abstract void WriteUInt32(uint val, string name);
178
179 [CLSCompliant(false)]
180 protected abstract void WriteUInt64(ulong val, string name);
181
182 protected abstract void WriteValueType(object obj, string name, Type memberType);
183}
virtual int Count
Definition Queue.cs:230
virtual void Enqueue(object? obj)
Definition Queue.cs:345
virtual ? object Dequeue()
Definition Queue.cs:367
static decimal ToDecimal(object? value)
Definition Convert.cs:2101
static long ToInt64(object? value)
Definition Convert.cs:1623
static float ToSingle(object? value)
Definition Convert.cs:1881
static int ToInt32(object? value)
Definition Convert.cs:1320
static DateTime ToDateTime(DateTime value)
Definition Convert.cs:2211
static short ToInt16(object? value)
Definition Convert.cs:1038
static byte ToByte(object? value)
Definition Convert.cs:900
static uint ToUInt32(object? value)
Definition Convert.cs:1470
static ulong ToUInt64(object? value)
Definition Convert.cs:1738
static char ToChar(object? value)
Definition Convert.cs:618
static ushort ToUInt16(object? value)
Definition Convert.cs:1177
static sbyte ToSByte(object? value)
Definition Convert.cs:745
static double ToDouble(object? value)
Definition Convert.cs:1991
static bool ToBoolean([NotNullWhen(true)] object? value)
Definition Convert.cs:508
static CultureInfo InvariantCulture
void WriteDouble(double val, string name)
void WriteBoolean(bool val, string name)
void WriteUInt32(uint val, string name)
void Serialize(Stream serializationStream, object graph)
void WriteInt32(int val, string name)
void WriteValueType(object obj, string name, Type memberType)
object Deserialize(Stream serializationStream)
virtual long Schedule(object? obj)
Definition Formatter.cs:47
void WriteUInt16(ushort val, string name)
virtual void WriteMember(string memberName, object? data)
Definition Formatter.cs:88
void WriteTimeSpan(TimeSpan val, string name)
virtual ? object GetNext(out long objID)
Definition Formatter.cs:31
void WriteUInt64(ulong val, string name)
void WriteChar(char val, string name)
void WriteInt64(long val, string name)
void WriteByte(byte val, string name)
void WriteSingle(float val, string name)
void WriteInt16(short val, string name)
void WriteSByte(sbyte val, string name)
void WriteObjectRef(object? obj, string name, Type memberType)
void WriteDateTime(DateTime val, string name)
void WriteArray(object obj, string name, Type memberType)
void WriteDecimal(decimal val, string name)
virtual long GetId(object obj, out bool firstTime)
virtual long HasId(object obj, out bool firstTime)
static string Serialization_NoID
Definition SR.cs:24
Definition SR.cs:7