Skip to content

Why doesn't BCL have methods like DateTime.WriteTo(TextWriter) etc. #116094

Answered by huoyaoyuan
TahirAhmadov asked this question in Ideas
Discussion options

You must be logged in to vote

Why doesn't BCL have methods like DateTime.WriteTo(TextWriter) etc.

This is against layering. Data types are core while TextWriter is at a higher layer. Efficiently writing to TextWriter isn't special than writing to other things: just format the object into a buffer of UTF-8 or UTF-16, then copy the buffer to any writer. Or, just format to the destination buffer directly.

This lead to the current solution: interpolated string handler with IFormattable/IUtf8Formattable. StringBuilder already implements this scheme.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by teo-tsirpanis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants