Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/ThisAssembly.Constants/CSharp.sbntxt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{~ if $0.Comment ~}}
{{ $0.Comment }}
{{~ else ~}}
/// => @"{{ $0.Value }}"
/// => @"{{ $0.EscapedValue }}"
{{~ end ~}}
/// </summary>
{{- end -}}
Expand Down
5 changes: 3 additions & 2 deletions src/ThisAssembly.Constants/ConstantsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Devlooped.Sponsors;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand Down Expand Up @@ -93,9 +94,9 @@ void GenerateConstant(SourceProductionContext spc,
}

if (comment != null)
comment = "/// " + string.Join(Environment.NewLine + "/// ", comment.Trim().Replace("\\n", Environment.NewLine).Trim(['\r', '\n']).Split([Environment.NewLine], StringSplitOptions.None));
comment = "/// " + string.Join(Environment.NewLine + "/// ", new XText(comment).ToString().Trim().Replace("\\n", Environment.NewLine).Trim(['\r', '\n']).Split([Environment.NewLine], StringSplitOptions.None));
else
comment = "/// " + string.Join(Environment.NewLine + "/// ", value.Replace("\\n", Environment.NewLine).Trim(['\r', '\n']).Split([Environment.NewLine], StringSplitOptions.None));
comment = "/// " + string.Join(Environment.NewLine + "/// ", new XText(value).ToString().Replace("\\n", Environment.NewLine).Trim(['\r', '\n']).Split([Environment.NewLine], StringSplitOptions.None));

// Revert normalization of newlines performed in MSBuild to workaround the limitation in editorconfig.
var rootArea = Area.Load([new(name, value.Replace("\\n", Environment.NewLine).Trim(['\r', '\n']), comment, type ?? "string"),], root, rootComment);
Expand Down
1 change: 1 addition & 0 deletions src/ThisAssembly.Constants/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@ static Area GetArea(Area area, IEnumerable<string> areaPath)
[DebuggerDisplay("{Name} = {Value}")]
record Constant(string Name, string? Value, string? Comment, string Type = "string")
{
public string? EscapedValue => Value == null ? null : new XText(Value).ToString();
public bool IsText => Type.Equals("string", StringComparison.OrdinalIgnoreCase);
}
2 changes: 2 additions & 0 deletions src/ThisAssembly.Tests/ThisAssembly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<NoWarn>CS0618;CS8981;TA100;$(NoWarn)</NoWarn>
<PackageScribanIncludeSource>false</PackageScribanIncludeSource>
<ProjectFile>$([System.IO.File]::ReadAllText($(MSBuildProjectFullPath)))</ProjectFile>
<ProjectFileComment>$(ProjectFile)</ProjectFileComment>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>
Expand Down Expand Up @@ -71,6 +72,7 @@
<ProjectProperty Include="Foo" />
<ProjectProperty Include="Description" />
<ProjectProperty Include="Multiline" />
<ProjectProperty Include="ProjectFileComment" Comment="Full project contents" />
<ProjectProperty Include="ProjectFile" />
<Constant Include="Foo.Raw" Value="$(Multiline)" Comment="$(Multiline)" />
<Constant Include="Foo.Bar" Value="Baz" Comment="Yay!" />
Expand Down