Skip to content

Commit 31314db

Browse files
authored
Merge pull request #51 from filzrev/chore-fix-mixed-line-endings
chore: Fix mixed line endings of source generated files
2 parents d2c2302 + f6e1859 commit 31314db

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/ZLinq.DropInGenerator/DropInGenerator.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace {{attribute.GenerateNamespace}}
105105
}
106106

107107
var hintName = resourceName.Replace("ZLinq.DropInGenerator.ResourceCodes.", "ZLinq.DropIn.").Replace(".cs", ".g.cs");
108-
context.AddSource($"{hintName}", sb.ToString());
108+
context.AddSource($"{hintName}", sb.ToString().ReplaceLineEndings());
109109
}
110110
}
111111

@@ -155,3 +155,23 @@ public static DiagnosticDescriptor Create(int id, string title, string messageFo
155155
1,
156156
"ZLinqDropIn AssemblyAttribute is not found, you need to add like [assembly: ZLinq.ZLinqDropInAttribute(\"ZLinq.DropIn\", ZLinq.DropInGenerateTypes.Array)].");
157157
}
158+
159+
internal static class StringExtensions
160+
{
161+
public static string ReplaceLineEndings(this string input)
162+
{
163+
#pragma warning disable RS1035
164+
return ReplaceLineEndings(input, Environment.NewLine);
165+
#pragma warning restore RS1035
166+
}
167+
168+
public static string ReplaceLineEndings(this string text, string replacementText)
169+
{
170+
text = text.Replace("\r\n", "\n");
171+
172+
if (replacementText != "\n")
173+
text = text.Replace("\n", replacementText);
174+
175+
return text;
176+
}
177+
}

0 commit comments

Comments
 (0)