Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WeGameHelper.cs
Go to the documentation of this file.
1using System.IO;
4using System.Text;
5
7
8public class WeGameHelper
9{
10 [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
11 private static extern void OutputDebugString(string message);
12
13 public static void WriteDebugString(string format, params object[] args)
14 {
15 _ = "[WeGame] - " + format;
16 }
17
18 public static string Serialize<T>(T data)
19 {
20 DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(T));
21 using MemoryStream memoryStream = new MemoryStream();
22 dataContractJsonSerializer.WriteObject((Stream)memoryStream, (object)data);
23 memoryStream.Position = 0L;
24 using StreamReader streamReader = new StreamReader(memoryStream, Encoding.UTF8);
25 return streamReader.ReadToEnd();
26 }
27
28 public static void UnSerialize<T>(string str, out T data)
29 {
30 using MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(str));
31 DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(T));
32 data = (T)dataContractJsonSerializer.ReadObject((Stream)stream);
33 }
34}
static Encoding Unicode
Definition Encoding.cs:519
static Encoding UTF8
Definition Encoding.cs:526
static void WriteDebugString(string format, params object[] args)
static void UnSerialize< T >(string str, out T data)
static string Serialize< T >(T data)
static void OutputDebugString(string message)