开发者

Inconsistent Line Endings Error

开发者 https://www.devze.com 2023-02-25 04:53 出处:网络
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

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:

  1. Don't use CrLf - that's a backwards compatibility thing. Use Environment.NewLine

  2. Your example is not a complete block of compilable code, your errant alternate new line chars could be from another part of your code.

  3. 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?

  4. Don't use lots of += with strings, use a StringBuilder instance instead. You can also use a TextWriter or StreamWriter which includes a WriteLine method.

  5. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消