@@ -44,6 +44,7 @@ internal CSharpFormattingOptionsContainer(CSharpFormattingOptionsContainer paren
4444 this . parent = parent ;
4545 this . activeOptions = new HashSet < string > ( ) ;
4646 Reset ( ) ;
47+ cachedOptions = CreateOptions ( ) ;
4748 }
4849
4950 public CSharpFormattingOptionsContainer Parent
@@ -81,7 +82,7 @@ private void OnPropertyChanged(string propertyName)
8182 PropertyChanged ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
8283 }
8384 }
84-
85+
8586 #endregion
8687
8788 private void HandlePropertyChanged ( object sender , PropertyChangedEventArgs e )
@@ -120,33 +121,6 @@ public object GetOption(string option)
120121 return null ;
121122 }
122123
123- /// <summary>
124- /// Retrieves the value of a formatting option where desired type and option name are defined by a
125- /// property getter on <see cref="ICSharpCode.NRefactory.CSharp.CSharpFormattingOptions"/>.
126- /// Searches in current and (if nothing set here) parent containers.
127- /// </summary>
128- /// <param name="propertyGetter">
129- /// Property getter lambda expression
130- /// (example: o => o.IndentStructBody)
131- /// </param>
132- /// <returns>True, if option with given type could be found in hierarchy. False otherwise.</returns>
133- public T GetEffectiveOption < T > ( Expression < Func < CSharpFormattingOptions , T > > propertyGetter )
134- where T : struct
135- {
136- // Get name of property (to look for in dictionary)
137- string optionName = null ;
138- MemberExpression memberExpression = propertyGetter . Body as MemberExpression ;
139- if ( memberExpression != null ) {
140- optionName = memberExpression . Member . Name ;
141- var val = GetEffectiveOption ( optionName ) ;
142- if ( val is T ) {
143- return ( T ) val ;
144- }
145- }
146-
147- return default ( T ) ;
148- }
149-
150124 /// <summary>
151125 /// Retrieves the value of a formatting option by looking at current and (if nothing set here) parent
152126 /// containers.
@@ -160,9 +134,11 @@ public object GetEffectiveOption(string option)
160134 do
161135 {
162136 object val = null ;
163- PropertyInfo propertyInfo = typeof ( CSharpFormattingOptions ) . GetProperty ( option ) ;
164- if ( propertyInfo != null ) {
165- val = propertyInfo . GetValue ( container . cachedOptions ) ;
137+ if ( container . activeOptions . Contains ( option ) ) {
138+ PropertyInfo propertyInfo = typeof ( CSharpFormattingOptions ) . GetProperty ( option ) ;
139+ if ( propertyInfo != null ) {
140+ val = propertyInfo . GetValue ( container . cachedOptions ) ;
141+ }
166142 }
167143 if ( val != null ) {
168144 return val ;
@@ -241,7 +217,7 @@ private CSharpFormattingOptions CreateOptions()
241217 propertyInfo . SetValue ( outputOptions , val ) ;
242218 }
243219 }
244-
220+
245221 return outputOptions ;
246222 }
247223
0 commit comments