diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs index 469101697d..4f34d46c45 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs @@ -44,6 +44,7 @@ namespace CSharpBinding.FormattingStrategy this.parent = parent; this.activeOptions = new HashSet(); Reset(); + cachedOptions = CreateOptions(); } public CSharpFormattingOptionsContainer Parent @@ -81,7 +82,7 @@ namespace CSharpBinding.FormattingStrategy PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } - + #endregion private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) @@ -120,33 +121,6 @@ namespace CSharpBinding.FormattingStrategy return null; } - /// - /// Retrieves the value of a formatting option where desired type and option name are defined by a - /// property getter on . - /// Searches in current and (if nothing set here) parent containers. - /// - /// - /// Property getter lambda expression - /// (example: o => o.IndentStructBody) - /// - /// True, if option with given type could be found in hierarchy. False otherwise. - public T GetEffectiveOption(Expression> propertyGetter) - where T : struct - { - // Get name of property (to look for in dictionary) - string optionName = null; - MemberExpression memberExpression = propertyGetter.Body as MemberExpression; - if (memberExpression != null) { - optionName = memberExpression.Member.Name; - var val = GetEffectiveOption(optionName); - if (val is T) { - return (T) val; - } - } - - return default(T); - } - /// /// Retrieves the value of a formatting option by looking at current and (if nothing set here) parent /// containers. @@ -160,9 +134,11 @@ namespace CSharpBinding.FormattingStrategy do { object val = null; - PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); - if (propertyInfo != null) { - val = propertyInfo.GetValue(container.cachedOptions); + if (container.activeOptions.Contains(option)) { + PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); + if (propertyInfo != null) { + val = propertyInfo.GetValue(container.cachedOptions); + } } if (val != null) { return val; @@ -241,7 +217,7 @@ namespace CSharpBinding.FormattingStrategy propertyInfo.SetValue(outputOptions, val); } } - + return outputOptions; } diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs index 7625122d41..74648d2af1 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs @@ -39,6 +39,7 @@ namespace CSharpBinding.FormattingStrategy // Load global settings GlobalOptions = new CSharpFormattingOptionsPersistence( SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer()); + GlobalOptions.Load(); // Handlers for solution loading/unloading SD.ProjectService.SolutionOpened += SolutionOpened; @@ -66,7 +67,7 @@ namespace CSharpBinding.FormattingStrategy // Lazily create options container projectOptions[key] = new CSharpFormattingOptionsPersistence( csproject.ExtensionProperties, - new CSharpFormattingOptionsContainer(SolutionOptions.OptionsContainer)); + new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer)); // HACK! } return projectOptions[key];