I wrote a software for auto-generating some lines of code. However when I do a copy and paste of that code in a class after reopening it again I conf开发者_如何学Pythonront an Inconsistent Line Ending Erros. How is that so? Where the problem lies and how can I fix it? it is about carriege return and line feeds.! Sample of that class:
txtResult.Text += " End Get" + CrLf
txtResult.Text += " Set(ByVal Value As " + GeneratePropertyCast(para.DbType) + ")" + CrLf
txtResult.Text += " Item("
txtResult.Text += GeneratePropertyColumn(para.ParameterName) + ")= Value" + CrLf
txtResult.Text += " End Set" + CrLf
txtResult.Text += "End Property" + CrLf
I'm a little unclear on exactly where the issue is, but it looks like you're building VB.Net code in C#, and that you're getting the inconsistent line ending errors for that code in VB.
Ok, so some ideas to try that might help:
Don't use
CrLf
- that's a backwards compatibility thing. UseEnvironment.NewLine
Your example is not a complete block of compilable code, your errant alternate new line chars could be from another part of your code.
Visual Studio usually auto-fixes inconsistent line endings, for instance if you past a snippet from the web. What are you pasting the code from and into?
Don't use lots of
+=
with strings, use aStringBuilder
instance instead. You can also use aTextWriter
orStreamWriter
which includes aWriteLine
method.Or, even better, .Net has a load of CodeDom stuff that lets you build up code by specifying what you want rather than the raw code.
Depending on where you actually get the error (when opening the code posted above, or when opening the code generated by the code above), I would suggest you to open your files with a hex editor and check if all the line endings fit "0D 0A".
If you are working with any other platform then windows (linux, mac) the line endings you need are different.
Take a look on Wikipedia to ensure your using the right endings.
精彩评论