Skip to content

Commit 7e1b105

Browse files
Merge pull request #27193 from Therzok/patch-1
Expand persister deserialization to also take into account string and accessibility modifiers
2 parents 717accb + 00d0424 commit 7e1b105

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.ComponentModel.Composition;
77
using System.Diagnostics;
88
using System.Linq;
9+
using System.Reflection;
910
using System.Runtime.InteropServices;
1011
using System.Xml.Linq;
1112
using Microsoft.CodeAnalysis.CodeStyle;
@@ -141,17 +142,9 @@ public bool TryFetch(OptionKey optionKey, out object value)
141142
value = Enum.ToObject(optionKey.Option.Type, value);
142143
}
143144
}
144-
else if (optionKey.Option.Type == typeof(CodeStyleOption<bool>))
145+
else if (typeof(ICodeStyleOption).IsAssignableFrom (optionKey.Option.Type))
145146
{
146-
return DeserializeCodeStyleOption<bool>(ref value);
147-
}
148-
else if (optionKey.Option.Type == typeof(CodeStyleOption<ExpressionBodyPreference>))
149-
{
150-
return DeserializeCodeStyleOption<ExpressionBodyPreference>(ref value);
151-
}
152-
else if (optionKey.Option.Type == typeof(CodeStyleOption<ParenthesesPreference>))
153-
{
154-
return DeserializeCodeStyleOption<ParenthesesPreference>(ref value);
147+
return DeserializeCodeStyleOption(ref value, optionKey.Option.Type);
155148
}
156149
else if (optionKey.Option.Type == typeof(NamingStylePreferences))
157150
{
@@ -202,13 +195,15 @@ public bool TryFetch(OptionKey optionKey, out object value)
202195
return true;
203196
}
204197

205-
private bool DeserializeCodeStyleOption<T>(ref object value)
198+
private bool DeserializeCodeStyleOption(ref object value, Type type)
206199
{
207200
if (value is string serializedValue)
208201
{
209202
try
210203
{
211-
value = CodeStyleOption<T>.FromXElement(XElement.Parse(serializedValue));
204+
var fromXElement = type.GetMethod(nameof(CodeStyleOption<object>.FromXElement), BindingFlags.Public | BindingFlags.Static);
205+
206+
value = fromXElement.Invoke(null, new object[] { XElement.Parse(serializedValue) });
212207
return true;
213208
}
214209
catch (Exception)

0 commit comments

Comments
 (0)