Skip to content

Commit f99c957

Browse files
committed
AppendIndentedLine
1 parent a9feab1 commit f99c957

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

sdk/eventgrid/Azure.Messaging.EventGrid/EventGridSourceGenerator/src/EventGridSourceGenerator.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,21 @@ public static class SystemEventNames
182182
SystemEventNode sysEvent = systemEvents[i];
183183

184184
// Add the ref docs for each constant
185-
sourceBuilder.AppendLine($"{Indent}{Indent}/// <summary>");
186-
sourceBuilder.AppendLine(
185+
sourceBuilder.AppendIndentedLine(2, "/// <summary>");
186+
sourceBuilder.AppendIndentedLine(2,
187187
!isSystemEventsLibrary
188-
? $"{Indent}{Indent}/// The value of the Event Type stored in <see cref=\"EventGridEvent.EventType\"/> and <see cref=\"CloudEvent.Type\"/> "
189-
: $"{Indent}{Indent}/// The value of the Event Type stored in <see cref=\"CloudEvent.Type\"/> ");
188+
? "/// The value of the Event Type stored in <see cref=\"EventGridEvent.EventType\"/> and <see cref=\"CloudEvent.Type\"/> "
189+
: "/// The value of the Event Type stored in <see cref=\"CloudEvent.Type\"/> ");
190190

191-
sourceBuilder.AppendLine($"{Indent}{Indent}/// for the <see cref=\"{sysEvent.EventName}\"/> system event.");
192-
sourceBuilder.AppendLine($"{Indent}{Indent}/// </summary>");
191+
sourceBuilder.AppendIndentedLine(2, $"/// for the <see cref=\"{sysEvent.EventName}\"/> system event.");
192+
sourceBuilder.AppendIndentedLine(2, "/// </summary>");
193193

194194
// Add the constant
195-
sourceBuilder.AppendLine($"{Indent}{Indent}public const string {sysEvent.EventConstantName} = {sysEvent.EventType};");
195+
sourceBuilder.AppendIndentedLine(2, $"public const string {sysEvent.EventConstantName} = {sysEvent.EventType};");
196196
}
197197

198-
sourceBuilder.Append($@"{Indent}}}
199-
}}");
198+
sourceBuilder.AppendIndentedLine(1, @"}
199+
}");
200200
return sourceBuilder.ToString();
201201
}
202202

@@ -225,14 +225,14 @@ public static object AsSystemEventData(string eventType, JsonElement data)
225225
foreach (SystemEventNode sysEvent in systemEvents)
226226
{
227227
// Add each an entry for each system event to the dictionary containing a mapping from constant name to deserialization method.
228-
sourceBuilder.AppendLine(
229-
$"{Indent}{Indent}{Indent}if (eventTypeSpan.Equals(SystemEventNames.{sysEvent.EventConstantName}.AsSpan(), StringComparison.OrdinalIgnoreCase))");
230-
sourceBuilder.AppendLine(
231-
$"{Indent}{Indent}{Indent}{Indent}return {sysEvent.EventName}.{sysEvent.DeserializeMethod}(data{(isSystemEventsLibrary ? ", null" : string.Empty)});");
228+
sourceBuilder.AppendIndentedLine(3,
229+
$"if (eventTypeSpan.Equals(SystemEventNames.{sysEvent.EventConstantName}.AsSpan(), StringComparison.OrdinalIgnoreCase))");
230+
sourceBuilder.AppendIndentedLine(4,
231+
$"return {sysEvent.EventName}.{sysEvent.DeserializeMethod}(data{(isSystemEventsLibrary ? ", null" : string.Empty)});");
232232
}
233-
sourceBuilder.AppendLine($"{Indent}{Indent}{Indent}return null;");
234-
sourceBuilder.AppendLine($"{Indent}{Indent}}}");
235-
sourceBuilder.AppendLine($"{Indent}}}");
233+
sourceBuilder.AppendIndentedLine(3, "return null;");
234+
sourceBuilder.AppendIndentedLine(2, "}");
235+
sourceBuilder.AppendIndentedLine(1, "}");
236236
sourceBuilder.AppendLine("}");
237237

238238
return sourceBuilder.ToString();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Text;
5+
6+
namespace Azure.EventGrid.Messaging.SourceGeneration
7+
{
8+
internal static class StringBuilderExtensions
9+
{
10+
public static void AppendIndentedLine(this StringBuilder sb, int indentLevel, string text)
11+
{
12+
sb.Append(' ', indentLevel * 4);
13+
sb.AppendLine(text);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)