private void SetXmlOption <T>(Option2 <CodeStyleOption2 <T> > option, string value)
        {
            var convertedValue = CodeStyleOption2 <T> .FromXElement(XElement.Parse(value));

            _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
                                                                              .WithChangedOption(option, convertedValue)));
        }
        private void SetXmlOption(PerLanguageOption2 <CodeStyleOption2 <bool> > option, string value)
        {
            var convertedValue = CodeStyleOption2 <bool> .FromXElement(XElement.Parse(value));

            _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
                                                                              .WithChangedOption(option, LanguageNames.CSharp, convertedValue)));
        }
        public void TestOptionSerialization2()
        {
            // Verify that ExpressionBodyPreference-options can migrate to bool-options.
            var option = new CodeStyleOption2 <ExpressionBodyPreference>(
                ExpressionBodyPreference.Never,
                NotificationOption2.Silent
                );
            var serialized   = option.ToXElement();
            var deserialized = CodeStyleOption2 <bool> .FromXElement(serialized);

            Assert.False(deserialized.Value);

            option = new CodeStyleOption2 <ExpressionBodyPreference>(
                ExpressionBodyPreference.WhenPossible,
                NotificationOption2.Silent
                );
            serialized   = option.ToXElement();
            deserialized = CodeStyleOption2 <bool> .FromXElement(serialized);

            Assert.True(deserialized.Value);

            // This new values can't actually translate back to a bool.  So we'll just get the default
            // value for this option.
            option = new CodeStyleOption2 <ExpressionBodyPreference>(
                ExpressionBodyPreference.WhenOnSingleLine,
                NotificationOption2.Silent
                );
            serialized   = option.ToXElement();
            deserialized = CodeStyleOption2 <bool> .FromXElement(serialized);

            Assert.Equal(default, deserialized.Value);
Beispiel #4
0
        public void TestOptionSerialization1()
        {
            // Verify that bool-options can migrate to ExpressionBodyPreference-options.
            var option = new CodeStyleOption2<bool>(false, NotificationOption2.Silent);
            var serialized = option.ToXElement();
            var deserialized = CodeStyleOption2<ExpressionBodyPreference>.FromXElement(serialized);

            Assert.Equal(ExpressionBodyPreference.Never, deserialized.Value);

            option = new CodeStyleOption2<bool>(true, NotificationOption2.Silent);
            serialized = option.ToXElement();
            deserialized = CodeStyleOption2<ExpressionBodyPreference>.FromXElement(serialized);

            Assert.Equal(ExpressionBodyPreference.WhenPossible, deserialized.Value);
        }