-
Notifications
You must be signed in to change notification settings - Fork 0
/
Serializer.cs
77 lines (68 loc) · 2.22 KB
/
Serializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using TFT_Engine.Components;
namespace TFT_Engine
{
public class Element<T>
{
[XmlAttribute] public T value { get; set; }
}
public class CharInfo
{
public string Name { get; set; }
public string TeamID { get; set; }
public string HashCode { get; set; }
}
public class CharInfoWrapper
{
[XmlArrayItem("Character")]
[XmlArray("Characters")]
public List<CharInfo> CharInfos { get; set; }
}
public class StatInfo
{
public Element<string> CharacterHashCode;
public Statistics stats;
}
public class StatInfoWrapper
{
/*[XmlArrayItem("Stats")]
[XmlArray("Stat")]*/
[XmlElement] public List<StatInfo> StatInfos { get; set; }
}
public class Serializer
{
public static string CharacterInfos(CharList c)
{
List<CharInfo> CharInfoTemp = new();
foreach (var character in c)
CharInfoTemp.Add(new CharInfo
{
Name = character.Name,
TeamID = character.TeamId.ToString(),
HashCode = character.GetHashCode().ToString()
});
XmlSerializer xs = new(typeof(CharInfoWrapper));
CharInfoWrapper wrapper = new() { CharInfos = CharInfoTemp };
using var writer = new StringWriter();
xs.Serialize(writer, wrapper);
return writer.ToString();
}
public static string CharacterStats(CharList c)
{
List<StatInfo> StatInfoTemp = new();
foreach (var character in c)
StatInfoTemp.Add(new StatInfo
{
CharacterHashCode = new Element<string> { value = character.GetHashCode().ToString() },
stats = character.CurrentStats
});
XmlSerializer xs = new(typeof(StatInfoWrapper));
StatInfoWrapper wrapper = new() { StatInfos = StatInfoTemp };
using var writer = new StringWriter();
xs.Serialize(writer, wrapper);
return writer.ToString();
}
}
}