From 93bc6dca9670feb60282f06eda19b18ebc21550a Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 9 Mar 2023 18:30:39 +0100 Subject: [PATCH] Use raw strings for quoted code in extensions generator --- bld/ExtensionsGenerator/Program.cs | 105 +++++++++++++++-------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/bld/ExtensionsGenerator/Program.cs b/bld/ExtensionsGenerator/Program.cs index f058842af..d275c3272 100644 --- a/bld/ExtensionsGenerator/Program.cs +++ b/bld/ExtensionsGenerator/Program.cs @@ -290,57 +290,62 @@ select Argument(IdentifierName(p.Identifier)), .WithSemicolonToken(ParseToken(";").WithTrailingTrivia(LineFeed)) } into m - select (!noClassLead ? $@" - /// {m.Name} extension. - - [GeneratedCode(""{thisAssemblyName.Name}"", ""{thisAssemblyName.Version}"")]" : null) + $@" - public static partial class {m.Name}Extension - {{ -{string.Join(null, from mo in m.Overloads select mo.ToFullString())} - }}"; - - var template = $@" -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// -// Licensed under the Apache License, Version 2.0 (the ""License""); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ""AS IS"" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#endregion - -// This code was generated by a tool. Any changes made manually will be lost -// the next time this code is regenerated. - -#nullable enable // required for auto-generated sources (see below why) - -// > Older code generation strategies may not be nullable aware. Setting the -// > project-level nullable context to ""enable"" could result in many -// > warnings that a user is unable to fix. To support this scenario any syntax -// > tree that is determined to be generated will have its nullable state -// > implicitly set to ""disable"", regardless of the overall project state. -// -// Source: https://github.com/dotnet/roslyn/blob/70e158ba6c2c99bd3c3fc0754af0dbf82a6d353d/docs/features/nullable-reference-types.md#generated-code - -#pragma warning disable RS0041 // Public members should not use oblivious types - -namespace MoreLinq.Extensions -{{ -{string.Join("\n", imports)} -{string.Join("\n", classes)} -}} - "; + let classLead = !noClassLead + ? $$""" + + /// {{m.Name}} extension. + + [GeneratedCode("{{thisAssemblyName.Name}}", "{{thisAssemblyName.Version}}")] + """ + : null + select $$""" + {{classLead}} + public static partial class {{m.Name}}Extension + { + {{string.Join(null, from mo in m.Overloads select mo.ToFullString())}} + } + """; + + var template = $$""" + #region License and Terms + // MoreLINQ - Extensions to LINQ to Objects + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + #endregion + + // This code was generated by a tool. Any changes made manually will be lost + // the next time this code is regenerated. + + #nullable enable // required for auto-generated sources (see below why) + + // > Older code generation strategies may not be nullable aware. Setting the + // > project-level nullable context to "enable" could result in many + // > warnings that a user is unable to fix. To support this scenario any syntax + // > tree that is determined to be generated will have its nullable state + // > implicitly set to "disable", regardless of the overall project state. + // + // Source: https://github.com/dotnet/roslyn/blob/70e158ba6c2c99bd3c3fc0754af0dbf82a6d353d/docs/features/nullable-reference-types.md#generated-code + + #pragma warning disable RS0041 // Public members should not use oblivious types + + namespace MoreLinq.Extensions + { + {{string.Join("\n", imports)}} + {{string.Join("\n", classes)}} + } + """; - Console.WriteLine(template.Trim() - // normalize line endings - .Replace("\r", string.Empty, StringComparison.Ordinal) + Console.WriteLine(template.Replace("\r", string.Empty, StringComparison.Ordinal) .Replace("\n", Environment.NewLine, StringComparison.Ordinal)); }