Skip to content

Commit 67967a6

Browse files
cominternretailcoder
authored andcommitted
Fixed RootElement bug in XmlPersistanceService<T> (Closes #1516) (#1527)
* Added input validation and reconciliation to HotkeySettings * Fixed RootElement bug in XmlPersistanceService<T>
1 parent 61ae384 commit 67967a6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Rubberduck.SettingsProvider/XmlPersistanceService.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
@@ -76,7 +77,7 @@ public void Save(T toSerialize)
7677
else
7778
{
7879
var parent = doc.Descendants().FirstOrDefault(e => e.Name.LocalName.Equals(RootElement));
79-
Debug.Assert(parent != null);
80+
// ReSharper disable once PossibleNullReferenceException
8081
parent.Add(settings);
8182
}
8283
}
@@ -89,22 +90,21 @@ public void Save(T toSerialize)
8990

9091
private static XDocument GetConfigurationDoc(string file)
9192
{
93+
XDocument output;
9294
try
9395
{
94-
return XDocument.Load(file);
95-
}
96-
catch
97-
{
98-
var output = new XDocument();
99-
var root = output.Descendants(RootElement).FirstOrDefault();
100-
if (root == null)
96+
output = XDocument.Load(file);
97+
if (output.Descendants().FirstOrDefault(e => e.Name.LocalName.Equals(RootElement)) != null)
10198
{
102-
output.Add(new XElement(RootElement));
103-
root = output.Descendants(RootElement).FirstOrDefault();
99+
return output;
104100
}
105-
Debug.Assert(root != null);
106-
return output;
107101
}
102+
// ReSharper disable once EmptyGeneralCatchClause
103+
catch { }
104+
105+
output = new XDocument();
106+
output.Add(new XElement(RootElement));
107+
return output;
108108
}
109109
}
110110
}

0 commit comments

Comments
 (0)