Skip to content

Commit 93bc6dc

Browse files
authored
Use raw strings for quoted code in extensions generator
1 parent 498a5e7 commit 93bc6dc

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

bld/ExtensionsGenerator/Program.cs

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -290,57 +290,62 @@ select Argument(IdentifierName(p.Identifier)),
290290
.WithSemicolonToken(ParseToken(";").WithTrailingTrivia(LineFeed))
291291
}
292292
into m
293-
select (!noClassLead ? $@"
294-
/// <summary><c>{m.Name}</c> extension.</summary>
295-
296-
[GeneratedCode(""{thisAssemblyName.Name}"", ""{thisAssemblyName.Version}"")]" : null) + $@"
297-
public static partial class {m.Name}Extension
298-
{{
299-
{string.Join(null, from mo in m.Overloads select mo.ToFullString())}
300-
}}";
301-
302-
var template = $@"
303-
#region License and Terms
304-
// MoreLINQ - Extensions to LINQ to Objects
305-
//
306-
// Licensed under the Apache License, Version 2.0 (the ""License"");
307-
// you may not use this file except in compliance with the License.
308-
// You may obtain a copy of the License at
309-
//
310-
// http://www.apache.org/licenses/LICENSE-2.0
311-
//
312-
// Unless required by applicable law or agreed to in writing, software
313-
// distributed under the License is distributed on an ""AS IS"" BASIS,
314-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
315-
// See the License for the specific language governing permissions and
316-
// limitations under the License.
317-
#endregion
318-
319-
// This code was generated by a tool. Any changes made manually will be lost
320-
// the next time this code is regenerated.
321-
322-
#nullable enable // required for auto-generated sources (see below why)
323-
324-
// > Older code generation strategies may not be nullable aware. Setting the
325-
// > project-level nullable context to ""enable"" could result in many
326-
// > warnings that a user is unable to fix. To support this scenario any syntax
327-
// > tree that is determined to be generated will have its nullable state
328-
// > implicitly set to ""disable"", regardless of the overall project state.
329-
//
330-
// Source: https://github.com/dotnet/roslyn/blob/70e158ba6c2c99bd3c3fc0754af0dbf82a6d353d/docs/features/nullable-reference-types.md#generated-code
331-
332-
#pragma warning disable RS0041 // Public members should not use oblivious types
333-
334-
namespace MoreLinq.Extensions
335-
{{
336-
{string.Join("\n", imports)}
337-
{string.Join("\n", classes)}
338-
}}
339-
";
293+
let classLead = !noClassLead
294+
? $$"""
295+
296+
/// <summary><c>{{m.Name}}</c> extension.</summary>
297+
298+
[GeneratedCode("{{thisAssemblyName.Name}}", "{{thisAssemblyName.Version}}")]
299+
"""
300+
: null
301+
select $$"""
302+
{{classLead}}
303+
public static partial class {{m.Name}}Extension
304+
{
305+
{{string.Join(null, from mo in m.Overloads select mo.ToFullString())}}
306+
}
307+
""";
308+
309+
var template = $$"""
310+
#region License and Terms
311+
// MoreLINQ - Extensions to LINQ to Objects
312+
//
313+
// Licensed under the Apache License, Version 2.0 (the "License");
314+
// you may not use this file except in compliance with the License.
315+
// You may obtain a copy of the License at
316+
//
317+
// http://www.apache.org/licenses/LICENSE-2.0
318+
//
319+
// Unless required by applicable law or agreed to in writing, software
320+
// distributed under the License is distributed on an "AS IS" BASIS,
321+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
322+
// See the License for the specific language governing permissions and
323+
// limitations under the License.
324+
#endregion
325+
326+
// This code was generated by a tool. Any changes made manually will be lost
327+
// the next time this code is regenerated.
328+
329+
#nullable enable // required for auto-generated sources (see below why)
330+
331+
// > Older code generation strategies may not be nullable aware. Setting the
332+
// > project-level nullable context to "enable" could result in many
333+
// > warnings that a user is unable to fix. To support this scenario any syntax
334+
// > tree that is determined to be generated will have its nullable state
335+
// > implicitly set to "disable", regardless of the overall project state.
336+
//
337+
// Source: https://github.com/dotnet/roslyn/blob/70e158ba6c2c99bd3c3fc0754af0dbf82a6d353d/docs/features/nullable-reference-types.md#generated-code
338+
339+
#pragma warning disable RS0041 // Public members should not use oblivious types
340+
341+
namespace MoreLinq.Extensions
342+
{
343+
{{string.Join("\n", imports)}}
344+
{{string.Join("\n", classes)}}
345+
}
346+
""";
340347

341-
Console.WriteLine(template.Trim()
342-
// normalize line endings
343-
.Replace("\r", string.Empty, StringComparison.Ordinal)
348+
Console.WriteLine(template.Replace("\r", string.Empty, StringComparison.Ordinal)
344349
.Replace("\n", Environment.NewLine, StringComparison.Ordinal));
345350
}
346351

0 commit comments

Comments
 (0)