Skip to content

Commit 942de6b

Browse files
committed
Switch to XmlSerializer so order does not matter
1 parent c8fa856 commit 942de6b

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

src/Profile.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using System;
22
using System.IO;
3-
using System.Runtime.Serialization;
43
using System.Xml;
4+
using System.Xml.Serialization;
55

66
namespace DarkRift.Cli
77
{
88
/// <summary>
99
/// Holds a user's profile settings.
1010
/// </summary>
11-
[DataContract(Name = "Profile")]
12-
class Profile
11+
// Namespace here is because we used to use DataContractSerializer
12+
[XmlRoot(Namespace="http://schemas.datacontract.org/2004/07/DarkRift.Cli")]
13+
public class Profile
1314
{
1415
/// <summary>
1516
/// The DarkRift settings directory path.
@@ -24,13 +25,11 @@ class Profile
2425
/// <summary>
2526
/// The user's Unity Asset Store invoice number.
2627
/// </summary>
27-
[DataMember]
2828
public string InvoiceNumber { get; set; }
29-
29+
3030
/// <summary>
3131
/// The latest version we know of for DarkRift.
3232
/// </summary>
33-
[DataMember]
3433
public string LatestKnownDarkRiftVersion { get; set; }
3534

3635
/// <summary>
@@ -44,16 +43,16 @@ public static Profile Load()
4443
try {
4544
using (XmlReader reader = XmlReader.Create(Path.Combine(USER_DR_DIR, "profile.xml")))
4645
{
47-
DataContractSerializer ser = new DataContractSerializer(typeof(Profile));
48-
instance = (Profile)ser.ReadObject(reader, true);
46+
XmlSerializer ser = new XmlSerializer(typeof(Profile));
47+
instance = (Profile)ser.Deserialize(reader);
4948
}
5049
}
5150
catch (IOException)
5251
{
5352
instance = new Profile();
5453
}
5554
}
56-
55+
5756
return instance;
5857
}
5958

@@ -65,9 +64,9 @@ public void Save()
6564
Directory.CreateDirectory(USER_DR_DIR);
6665
using (XmlWriter writer = XmlWriter.Create(Path.Combine(USER_DR_DIR, "profile.xml"), new XmlWriterSettings { Indent = true }))
6766
{
68-
DataContractSerializer ser = new DataContractSerializer(typeof(Profile));
69-
ser.WriteObject(writer, this);
67+
XmlSerializer ser = new XmlSerializer(typeof(Profile));
68+
ser.Serialize(writer, this);
7069
}
7170
}
7271
}
73-
}
72+
}

src/Project.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using System;
21
using System.IO;
3-
using System.Runtime.Serialization;
42
using System.Xml;
3+
using System.Xml.Serialization;
54

65
namespace DarkRift.Cli
76
{
87
/// <summary>
98
/// Holds a project's settings.
109
/// </summary>
11-
[DataContract(Name = "Project")]
12-
class Project
10+
// Namespace here is because we used to use DataContractSerializer
11+
[XmlRoot(Namespace="http://schemas.datacontract.org/2004/07/DarkRift.Cli")]
12+
public class Project
1313
{
1414
/// <summary>
1515
/// The singleton instance of the profile class.
@@ -19,7 +19,6 @@ class Project
1919
/// <summary>
2020
/// The runtime settings.
2121
/// </summary>
22-
[DataMember]
2322
public Runtime Runtime { get; set; }
2423

2524
/// <summary>
@@ -33,16 +32,16 @@ public static Project Load()
3332
try {
3433
using (XmlReader reader = XmlReader.Create("Project.xml"))
3534
{
36-
DataContractSerializer ser = new DataContractSerializer(typeof(Project));
37-
instance = (Project)ser.ReadObject(reader, true);
35+
XmlSerializer ser = new XmlSerializer(typeof(Project));
36+
instance = (Project)ser.Deserialize(reader);
3837
}
3938
}
4039
catch (IOException)
4140
{
4241
instance = new Project();
4342
}
4443
}
45-
44+
4645
return instance;
4746
}
4847

@@ -53,8 +52,8 @@ public void Save()
5352
{
5453
using (XmlWriter writer = XmlWriter.Create("Project.xml", new XmlWriterSettings { Indent = true }))
5554
{
56-
DataContractSerializer ser = new DataContractSerializer(typeof(Project));
57-
ser.WriteObject(writer, this);
55+
XmlSerializer ser = new XmlSerializer(typeof(Project));
56+
ser.Serialize(writer, this);
5857
}
5958
}
6059

@@ -68,4 +67,4 @@ public static bool IsCurrentDirectoryAProject()
6867
return File.Exists("Project.xml");
6968
}
7069
}
71-
}
70+
}

src/Runtime.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
using System;
2-
using System.Runtime.Serialization;
32

43
namespace DarkRift.Cli
54
{
65
/// <summary>
76
/// Holds a project's runtime settings.
87
/// </summary>
9-
[DataContract(Name = "Runtime")]
10-
class Runtime
8+
public class Runtime
119
{
1210
/// <summary>
1311
/// The version of DarkRift to use.
1412
/// </summary>
15-
[DataMember]
1613
public String Version { get; set; }
1714

1815
/// <summary>
1916
/// If .NET core or .NET framework should be used.
2017
/// </summary>
21-
[DataMember]
2218
public ServerPlatform Platform { get; set; }
2319

2420
/// <summary>
2521
/// The tier of DarkRift to use.
2622
/// </summary>
27-
[DataMember]
2823
public ServerTier Tier { get; set; }
2924

25+
/// <summary>
26+
/// Creates a new Runtime configuration element.
27+
/// </summary>
28+
public Runtime()
29+
{
30+
}
31+
3032
/// <summary>
3133
/// Creates a new Runtime configuration element.
3234
/// </summary>

src/ServerPlatform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace DarkRift.Cli
44
/// <summary>
55
/// The .NET platform the server targets.
66
/// </summary>
7-
enum ServerPlatform
7+
public enum ServerPlatform
88
{
99
Framework,
1010
Core

src/ServerTier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ namespace DarkRift.Cli
33
/// <summary>
44
/// The tier of DarkRift server.
55
/// </summary>
6-
enum ServerTier
6+
public enum ServerTier
77
{
88
Free,
99
Pro
1010
}
11-
}
11+
}

src/VersionMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ public static VersionMetadata Parse(string jsonString)
3737
}
3838
}
3939
}
40-
}
40+
}

0 commit comments

Comments
 (0)