@@ -11,23 +11,23 @@ public CodeBuilder Append(
1111
1212 public CodeBuilder Append ( bool enabled ,
1313 [ InterpolatedStringHandlerArgument ( "" , nameof ( enabled ) ) ]
14- ref ConditionalCodeBuilderInterpolatedStringHandler builder ) => this ;
14+ ref CodeBuilderInterpolatedStringHandler builder ) => this ;
1515
1616 public CodeBuilder AppendLineRaw (
1717 [ InterpolatedStringHandlerArgument ( "" ) ]
1818 ref CodeBuilderInterpolatedStringHandler builder ) => AppendLine ( ) ;
1919
2020 public CodeBuilder AppendLineRaw ( bool enabled ,
2121 [ InterpolatedStringHandlerArgument ( "" , nameof ( enabled ) ) ]
22- ref ConditionalCodeBuilderInterpolatedStringHandler builder ) => enabled ? AppendLine ( ) : this ;
22+ ref CodeBuilderInterpolatedStringHandler builder ) => enabled ? AppendLine ( ) : this ;
2323
2424 public CodeBuilder AppendLine (
2525 [ InterpolatedStringHandlerArgument ( "" ) ]
2626 IndentedCodeBuilderInterpolatedStringHandler builder ) => AppendLine ( ) ;
2727
2828 public CodeBuilder AppendLine ( bool enabled ,
2929 [ InterpolatedStringHandlerArgument ( "" , nameof ( enabled ) ) ]
30- ConditionalIndentedCodeBuilderInterpolatedStringHandler builder ) => enabled ? AppendLine ( ) : this ;
30+ IndentedCodeBuilderInterpolatedStringHandler builder ) => enabled ? AppendLine ( ) : this ;
3131
3232 private void AppendFormatted ( IEnumerable < string > items , string ? format )
3333 {
@@ -76,51 +76,37 @@ private void AppendCommaIndented(IEnumerable<string> items)
7676
7777 [ InterpolatedStringHandler ]
7878 internal readonly struct CodeBuilderInterpolatedStringHandler (
79- int literalLength , int formattedCount , CodeBuilder codeBuilder )
80- {
81- public readonly void AppendLiteral ( string s ) => codeBuilder . Append ( s ) ;
82- public readonly void AppendFormatted ( string s ) => codeBuilder . Append ( s ) ;
83- public readonly void AppendFormatted ( IEnumerable < string > items , string ? format )
84- => codeBuilder . AppendFormatted ( items , format ) ;
85- }
86-
87- [ InterpolatedStringHandler ]
88- internal readonly struct ConditionalCodeBuilderInterpolatedStringHandler (
89- int literalLength , int formattedCount , CodeBuilder codeBuilder , bool enabled )
79+ int literalLength , int formattedCount , CodeBuilder codeBuilder , bool enabled = true )
9080 {
91- public readonly bool AppendLiteral ( string s ) { if ( enabled ) codeBuilder . Append ( s ) ; return enabled ; }
92- public readonly bool AppendFormatted ( string s ) { if ( enabled ) codeBuilder . Append ( s ) ; return enabled ; }
81+ public readonly bool AppendLiteral ( string s )
82+ { if ( enabled ) codeBuilder . Append ( s ) ; return enabled ; }
83+ public readonly bool AppendFormatted ( string s )
84+ { if ( enabled ) codeBuilder . Append ( s ) ; return enabled ; }
9385 public readonly bool AppendFormatted ( IEnumerable < string > items , string ? format )
9486 { if ( enabled ) codeBuilder . AppendFormatted ( items , format ) ; return enabled ; }
9587 }
9688
9789 [ InterpolatedStringHandler ]
9890 internal class IndentedCodeBuilderInterpolatedStringHandler (
99- int literalLength , int formattedCount , CodeBuilder codeBuilder )
91+ int literalLength , int formattedCount , CodeBuilder codeBuilder , bool enabled = true )
10092 {
10193 private bool _hasIndented ;
10294
103- private void EnsureIndent ( )
95+ private CodeBuilder EnsureIndent ( )
10496 {
105- if ( _hasIndented ) return ;
106- codeBuilder . AppendIndent ( ) ;
107- _hasIndented = true ;
97+ if ( ! _hasIndented )
98+ {
99+ codeBuilder . AppendIndent ( ) ;
100+ _hasIndented = true ;
101+ }
102+ return codeBuilder ;
108103 }
109104
110- public void AppendLiteral ( string s ) { EnsureIndent ( ) ; codeBuilder . Append ( s ) ; }
111- public void AppendFormatted ( string s ) { EnsureIndent ( ) ; codeBuilder . Append ( s ) ; }
112- public void AppendFormatted ( IEnumerable < string > items , string ? format )
113- { EnsureIndent ( ) ; codeBuilder . AppendFormatted ( items , format ) ; }
114- }
115-
116- [ InterpolatedStringHandler ]
117- internal class ConditionalIndentedCodeBuilderInterpolatedStringHandler (
118- int literalLength , int formattedCount , CodeBuilder codeBuilder , bool enabled )
119- : IndentedCodeBuilderInterpolatedStringHandler ( literalLength , formattedCount , codeBuilder )
120- {
121- public new bool AppendLiteral ( string s ) { if ( enabled ) base . AppendLiteral ( s ) ; return enabled ; }
122- public new bool AppendFormatted ( string s ) { if ( enabled ) base . AppendFormatted ( s ) ; return enabled ; }
123- public new bool AppendFormatted ( IEnumerable < string > items , string ? format )
124- { if ( enabled ) base . AppendFormatted ( items , format ) ; return enabled ; }
105+ public bool AppendLiteral ( string s )
106+ { if ( enabled ) EnsureIndent ( ) . Append ( s ) ; return enabled ; }
107+ public bool AppendFormatted ( string s )
108+ { if ( enabled ) EnsureIndent ( ) . Append ( s ) ; return enabled ; }
109+ public bool AppendFormatted ( IEnumerable < string > items , string ? format )
110+ { if ( enabled ) EnsureIndent ( ) . AppendFormatted ( items , format ) ; return enabled ; }
125111 }
126112}
0 commit comments