Skip to content

Commit

Permalink
Use raw strings for quoted code in extensions generator
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored Mar 9, 2023
1 parent 498a5e7 commit 93bc6dc
Showing 1 changed file with 55 additions and 50 deletions.
105 changes: 55 additions & 50 deletions bld/ExtensionsGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,57 +290,62 @@ select Argument(IdentifierName(p.Identifier)),
.WithSemicolonToken(ParseToken(";").WithTrailingTrivia(LineFeed))
}
into m
select (!noClassLead ? $@"
/// <summary><c>{m.Name}</c> extension.</summary>

[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
? $$"""

/// <summary><c>{{m.Name}}</c> extension.</summary>

[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));
}

Expand Down

0 comments on commit 93bc6dc

Please sign in to comment.