Replies: 3 comments 11 replies
-
What do you mean "implicit ToString"? Do you have an example? |
Beta Was this translation helpful? Give feedback.
-
Requests for the compiler (or just an analyzer in this case) should go to Roslyn or Roslyn-Analyzers. Do you have an example? That would help direct where this should go. Thanks! |
Beta Was this translation helpful? Give feedback.
-
This is what I am referring to:
prints
prints
The first is a bug that has happened numerous times in my 20+ year career. Sometimes that would be wanted, that is why I suggest a warning with a pragma or special character to say it's really what you meant to do. How often am I trying to get the type name back as a string versus having to get the values of a string back, but in haste, I don't finish the line of code the way I intended, but the compiler can't let me know I made an error, beause we just implicitly call ToString()? It's often enough. |
Beta Was this translation helpful? Give feedback.
-
It would be nice if the language compiler would generate a warning when you used an implicit ToString() on a type that is not a string or derivitave of string and you did not explicitly override ToString() in your type. The warning could be ignored with a pragma or a special character indicate you really meant it like variable.
ToString()
. This would save numerous software bugs where a type is sent in for a string value either through type converstion or concatenation with a string, and you end up with the Type as the string itself. It's plagued C# software for over 20 years. It seems like this could be a nice language feature.Beta Was this translation helpful? Give feedback.
All reactions