@@ -17,7 +17,9 @@ public partial class CSharpCodeBuilder
1717 /// </code>
1818 /// </example>
1919 public CSharpCodeBuilder AppendInterpolated (
20+ #pragma warning disable IDE0060 // Remove unused parameter
2021 [ InterpolatedStringHandlerArgument ( "" ) ] ref CSharpInterpolatedStringHandler handler
22+ #pragma warning restore IDE0060 // Remove unused parameter
2123 ) => this ;
2224
2325 /// <summary>
@@ -31,7 +33,9 @@ public CSharpCodeBuilder AppendInterpolated(
3133 /// </code>
3234 /// </example>
3335 public CSharpCodeBuilder AppendLineInterpolated (
36+ #pragma warning disable IDE0060 // Remove unused parameter
3437 [ InterpolatedStringHandlerArgument ( "" ) ] ref CSharpInterpolatedStringHandler handler
38+ #pragma warning restore IDE0060 // Remove unused parameter
3539 ) => AppendLine ( ) ;
3640
3741 internal void HandlerEnsureIndented ( ) => EnsureIndented ( ) ;
@@ -52,130 +56,4 @@ internal void HandlerRawAppend(ReadOnlySpan<char> value)
5256 }
5357 }
5458}
55-
56- /// <summary>
57- /// Custom interpolated string handler for <see cref="CSharpCodeBuilder"/>.
58- /// </summary>
59- /// <remarks>
60- /// This handler is instantiated by the compiler when an interpolated string is passed to
61- /// <see cref="CSharpCodeBuilder.AppendInterpolated"/> or <see cref="CSharpCodeBuilder.AppendLineInterpolated"/>.
62- /// It appends each literal and formatted part directly to the builder, applying indentation before
63- /// the first non-empty part on a new line.
64- /// </remarks>
65- [ InterpolatedStringHandler ]
66- public ref struct CSharpInterpolatedStringHandler
67- {
68- private readonly CSharpCodeBuilder _owner ;
69- private bool _indentEnsured ;
70-
71- /// <summary>
72- /// Initializes a new instance of the <see cref="CSharpInterpolatedStringHandler"/> struct.
73- /// </summary>
74- /// <param name="literalLength">The total length of all literal parts (hint for capacity).</param>
75- /// <param name="formattedCount">The number of formatted holes in the interpolated string.</param>
76- /// <param name="builder">The <see cref="CSharpCodeBuilder"/> to append to.</param>
77- public CSharpInterpolatedStringHandler ( int literalLength , int formattedCount , CSharpCodeBuilder builder )
78- {
79- _owner = builder ;
80- _indentEnsured = false ;
81- }
82-
83- private void EnsureIndented ( )
84- {
85- if ( ! _indentEnsured )
86- {
87- _owner . HandlerEnsureIndented ( ) ;
88- _indentEnsured = true ;
89- }
90- }
91-
92- /// <summary>Appends a literal string part of the interpolated string.</summary>
93- /// <param name="value">The literal string to append.</param>
94- public void AppendLiteral ( string ? value )
95- {
96- if ( string . IsNullOrEmpty ( value ) )
97- {
98- return ;
99- }
100-
101- EnsureIndented ( ) ;
102- _owner . HandlerRawAppend ( value ) ;
103- }
104-
105- /// <summary>Appends a formatted value from the interpolated string.</summary>
106- /// <typeparam name="T">The type of the value to format.</typeparam>
107- /// <param name="value">The value to append.</param>
108- public void AppendFormatted < T > ( T value )
109- {
110- var str = value ? . ToString ( ) ;
111- if ( string . IsNullOrEmpty ( str ) )
112- {
113- return ;
114- }
115-
116- EnsureIndented ( ) ;
117- _owner . HandlerRawAppend ( str ) ;
118- }
119-
120- /// <summary>Appends a formatted value with a format string from the interpolated string.</summary>
121- /// <typeparam name="T">The type of the value to format. Must implement <see cref="System.IFormattable"/>.</typeparam>
122- /// <param name="value">The value to append.</param>
123- /// <param name="format">The format string.</param>
124- public void AppendFormatted < T > ( T value , string ? format )
125- where T : System . IFormattable
126- {
127- var str = value ? . ToString ( format , CultureInfo . InvariantCulture ) ;
128- if ( string . IsNullOrEmpty ( str ) )
129- {
130- return ;
131- }
132-
133- EnsureIndented ( ) ;
134- _owner . HandlerRawAppend ( str ) ;
135- }
136-
137- /// <summary>Appends a formatted value with alignment from the interpolated string.</summary>
138- /// <typeparam name="T">The type of the value to format.</typeparam>
139- /// <param name="value">The value to append.</param>
140- /// <param name="alignment">Minimum width; negative values left-align.</param>
141- public void AppendFormatted < T > ( T value , int alignment )
142- {
143- var str = value ? . ToString ( ) ;
144- if ( str is null )
145- {
146- return ;
147- }
148-
149- str = alignment >= 0 ? str . PadLeft ( alignment ) : str . PadRight ( - alignment ) ;
150- EnsureIndented ( ) ;
151- _owner . HandlerRawAppend ( str ) ;
152- }
153-
154- /// <summary>Appends a formatted value with alignment and format string from the interpolated string.</summary>
155- /// <typeparam name="T">The type of the value to format. Must implement <see cref="System.IFormattable"/>.</typeparam>
156- /// <param name="value">The value to append.</param>
157- /// <param name="alignment">Minimum width; negative values left-align.</param>
158- /// <param name="format">The format string.</param>
159- public void AppendFormatted < T > ( T value , int alignment , string ? format )
160- where T : System . IFormattable
161- {
162- var str = value ? . ToString ( format , CultureInfo . InvariantCulture ) ?? string . Empty ;
163- str = alignment >= 0 ? str . PadLeft ( alignment ) : str . PadRight ( - alignment ) ;
164- EnsureIndented ( ) ;
165- _owner . HandlerRawAppend ( str ) ;
166- }
167-
168- /// <summary>Appends a <see cref="ReadOnlySpan{T}"/> value from the interpolated string.</summary>
169- /// <param name="value">The span to append.</param>
170- public void AppendFormatted ( ReadOnlySpan < char > value )
171- {
172- if ( value . IsEmpty )
173- {
174- return ;
175- }
176-
177- EnsureIndented ( ) ;
178- _owner . HandlerRawAppend ( value ) ;
179- }
180- }
18159#endif
0 commit comments