Skip to content

Commit 1dc011f

Browse files
Add a couple of common helpers to SourceWriter
1 parent 0df097c commit 1dc011f

File tree

2 files changed

+116
-98
lines changed

2 files changed

+116
-98
lines changed

src/Compiler/tools/RazorSyntaxGenerator/AbstractFileWriter.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,29 @@ private void WriteIndentIfNeeded()
133133
}
134134
}
135135

136+
/// <summary>
137+
/// Writes all <paramref name="values"/> with each value separated by a comma.
138+
/// </summary>
139+
/// <remarks>
140+
/// Values can be either <see cref="string"/>s or <see cref="IEnumerable{T}"/>s of
141+
/// <see cref="string"/>. All of these are flattened into a single sequence that is joined.
142+
/// Empty strings are ignored.
143+
/// </remarks>
144+
protected void WriteCommaSeparatedList(params IEnumerable<object> values)
145+
{
146+
Write(CommaJoin(values));
147+
}
148+
136149
/// <summary>
137150
/// Joins all the values together in <paramref name="values"/> into one string with each
138151
/// value separated by a comma. Values can be either <see cref="string"/>s or <see
139152
/// cref="IEnumerable{T}"/>s of <see cref="string"/>. All of these are flattened into a
140153
/// single sequence that is joined. Empty strings are ignored.
141154
/// </summary>
142-
protected static string CommaJoin(params object[] values)
155+
protected static string CommaJoin(params IEnumerable<object> values)
143156
=> Join(", ", values);
144157

145-
protected static string Join(string separator, params object[] values)
158+
protected static string Join(string separator, params IEnumerable<object> values)
146159
=> string.Join(separator, values.SelectMany(v => (v switch
147160
{
148161
string s => [s],
@@ -318,6 +331,7 @@ protected static bool HasErrors(Node n)
318331

319332
protected static string CamelCase(string name)
320333
{
334+
// Special logic to handle 'CSharp' correctly
321335
if (name.StartsWith("CSharp", StringComparison.OrdinalIgnoreCase))
322336
{
323337
name = "csharp" + name[6..];

0 commit comments

Comments
 (0)