You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When override get property TextWriter.NewLine, it does not affect the newline being used as a set on the property is required in order to set the backing field that is actually used. This is quite unintuitive as one would expect the overloaded get NewLine to be used, otherwise what is the point of it being overridable anyways?
Reproduction Steps
public sealed class SmileyStreamWriter(Stream stream, IFormatProvider formatProvider, bool leaveOpen)
: StreamWriter(stream, System.Text.Encoding.UTF8, -1, leaveOpen)
{
public override string NewLine => ":)";
public override IFormatProvider FormatProvider { get; } = formatProvider;
}
using var file = File.Open("test.txt", FileMode.CreateNew);
var sw = new SmileyStreamWriter(file, CultureInfo.InvariantCulture, leaveOpen: true)
sw.WriteLine("test"); // Writes test\r\n (or \n on unix).
Expected behavior
Expect to use the get override of newline.
Actual behavior
Uses platform default.
Regression?
No idea.
Known Workarounds
Use explicit NewLine set in constructor of derived class rendering overriding pointless.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered:
Description
When override get property TextWriter.NewLine, it does not affect the newline being used as a set on the property is required in order to set the backing field that is actually used. This is quite unintuitive as one would expect the overloaded get NewLine to be used, otherwise what is the point of it being overridable anyways?
Reproduction Steps
Expected behavior
Expect to use the get override of newline.
Actual behavior
Uses platform default.
Regression?
No idea.
Known Workarounds
Use explicit NewLine set in constructor of derived class rendering overriding pointless.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: