|
6 | 6 | using System.ComponentModel.Composition; |
7 | 7 | using System.Diagnostics; |
8 | 8 | using System.Linq; |
| 9 | +using System.Reflection; |
9 | 10 | using System.Runtime.InteropServices; |
10 | 11 | using System.Xml.Linq; |
11 | 12 | using Microsoft.CodeAnalysis.CodeStyle; |
@@ -141,17 +142,9 @@ public bool TryFetch(OptionKey optionKey, out object value) |
141 | 142 | value = Enum.ToObject(optionKey.Option.Type, value); |
142 | 143 | } |
143 | 144 | } |
144 | | - else if (optionKey.Option.Type == typeof(CodeStyleOption<bool>)) |
| 145 | + else if (typeof(ICodeStyleOption).IsAssignableFrom (optionKey.Option.Type)) |
145 | 146 | { |
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); |
155 | 148 | } |
156 | 149 | else if (optionKey.Option.Type == typeof(NamingStylePreferences)) |
157 | 150 | { |
@@ -202,13 +195,15 @@ public bool TryFetch(OptionKey optionKey, out object value) |
202 | 195 | return true; |
203 | 196 | } |
204 | 197 |
|
205 | | - private bool DeserializeCodeStyleOption<T>(ref object value) |
| 198 | + private bool DeserializeCodeStyleOption(ref object value, Type type) |
206 | 199 | { |
207 | 200 | if (value is string serializedValue) |
208 | 201 | { |
209 | 202 | try |
210 | 203 | { |
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) }); |
212 | 207 | return true; |
213 | 208 | } |
214 | 209 | catch (Exception) |
|
0 commit comments