Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.CodeStyle;
Expand Down Expand Up @@ -141,17 +142,9 @@ public bool TryFetch(OptionKey optionKey, out object value)
value = Enum.ToObject(optionKey.Option.Type, value);
}
}
else if (optionKey.Option.Type == typeof(CodeStyleOption<bool>))
else if (typeof(ICodeStyleOption).IsAssignableFrom (optionKey.Option.Type))
{
return DeserializeCodeStyleOption<bool>(ref value);
}
else if (optionKey.Option.Type == typeof(CodeStyleOption<ExpressionBodyPreference>))
{
return DeserializeCodeStyleOption<ExpressionBodyPreference>(ref value);
}
else if (optionKey.Option.Type == typeof(CodeStyleOption<ParenthesesPreference>))
{
return DeserializeCodeStyleOption<ParenthesesPreference>(ref value);
return DeserializeCodeStyleOption(ref value, optionKey.Option.Type);
}
else if (optionKey.Option.Type == typeof(NamingStylePreferences))
{
Expand Down Expand Up @@ -202,13 +195,15 @@ public bool TryFetch(OptionKey optionKey, out object value)
return true;
}

private bool DeserializeCodeStyleOption<T>(ref object value)
private bool DeserializeCodeStyleOption(ref object value, Type type)
{
if (value is string serializedValue)
{
try
{
value = CodeStyleOption<T>.FromXElement(XElement.Parse(serializedValue));
var fromXElement = type.GetMethod(nameof(CodeStyleOption<object>.FromXElement), BindingFlags.Public | BindingFlags.Static);

value = fromXElement.Invoke(null, new object[] { XElement.Parse(serializedValue) });
return true;
}
catch (Exception)
Expand Down