C# extension method to convert line endings in the string to the current Environment.NewLine.

/// <summary>
/// Converts line endings in the string to <see cref="Environment.NewLine"/>.
/// </summary>
public static string NormalizeLineEndings(this string str)
{
    return str.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine);
}