Jul 09, 2020 10:54 PM|PaulTheSmith|LINK
I can't think of a way to fix it globally (well, I can .... see below). The approach I would probably take in my code would be to create an Extension method.
public static class DisplayExtensions
public static ToDiplayString(this MySqlDateTime mySqlDateTime)
Of course, you can have multiple extensions .ToShortDateDisplayString(), .ToISODisplayString(), .ToLocalDisplayString(CultureInfo), you get the idea.
The 'fix' in your code would require a search for .ToString() and replace with .ToDisplayString() whenever it applies to a MySqlDateTime value.
FWIW - I, almost, never use the builtin .ToString() overrides to display information to end users. My mental model is that .ToString is a crude but effective debugging tool. I will create .ToString() overrides on my domain classes that display the important
parts in a simple way. It make debugging easier because the debugger makes extensive use of .ToString(). But for text that is seen by users I will create my own display methods - either in my domain classes or as extension methods for external classes.
It might a bit fussy but a simple search for ".ToString(" in my code lets me check that I have thought properly about how something should be displayed because there should not be any instances of ".ToString("
How to fix it globally? There is actually one way that I can think of and it is probably the 'right' way, in a sense. You could Branch the MySql/Connector project and fix the MySqlDateTime.ToString() method. Then your project would reference the 'fixed'
version of MySql/Connector and not need any changes in your codebase. I don't use MySql and have never been involved in the world of 'open source'. Is MySql open source? There seems to be some debate. Maybe you could investigate and perform a community
service by contributing to the code!
-OR- you could look into filing a bug report (the .ToString() method definitely violates the 'spirit' of all other .ToString() methods in .Net - in my opinion). Maybe it would get fixed in some later version...