Right?
Wrong!
The code.Escape() calls CSharpCodeProvider.CreateEscapedIdentifier() which does ... well nothing really. If the string contains a space, the result will contain a space. If it contains a dash, the result will contain a dash. Etc. etc. etc.
So far it seems the only thing it does is ... if the whole string matches a C# keyword, the method prepends @.
OK, let's see the docs.
CreateEscapedIdentifier | Creates an escaped identifier for the specified value. (Inherited from CodeDomProvider.) |
Any other candidates?
CreateValidIdentifier | Creates a valid identifier for the specified value. (Inherited from CodeDomProvider.) |
code.CreateValidIdentifier("Hello world") == "Hello world"
How's that a valid identifier I really do not know.
Funny thing is that code.IsValidIdentifier("Hello world") returns false. Just like code.IsValidIdentifier(code.CreateValidIdentifier("Hello world")) of course.
Thank you very much Microsoft once again!
Žádné komentáře:
Okomentovat