8000 Use raw strings for quoted code in extensions generator by atifaziz · Pull Request #983 · morelinq/MoreLINQ · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use raw strings for quoted code in extensions generator #983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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