Does VB.NET not allow line continuations over commented-out lines?

前端 未结 2 1421
你的背包
你的背包 2021-01-12 20:30

I just had this throw a compilation error while refactoring some legacy (hence VB.NET) unit tests, where I wanted to just comment out one of the sample inputs to MBUnit:

相关标签:
2条回答
  • 2021-01-12 21:10

    Yes, as far as I understand it, the problem is that your first line continuation adds the commented out line as part of the first line, and then the line continuation character on the commented out line is ignored since it's part of a comment so it ends up being:

    <RowTest> '<Row("Something")> _  <-- this line continuation character is ignored since it's commented out.
    <Row("SomethingElse")> _
    

    What would be needed to support this would be a way to end a comment other than a newline, but as it's usually not a problem and I think it would affect the compiling speed etc quite a bit since it would make it have to parse all comments I suppose it's not seen as worthwhile.

    0 讨论(0)
  • 2021-01-12 21:26

    I have a .[Rem] extension method to allow the in-place "commenting out" of fluent expressions. You could create a [Rem] attribute to do the same thing.

    <Row> _
    <[Rem]("<Row(""Something"")> _")> _
    <RowTest("SomethingElse")> _
    Sub Main
    
    End Sub
    
    ' Define other methods and classes here
    <AttributeUsage(AttributeTargets.All, AllowMultiple:=True)> _
    Class [Rem]
        Inherits Attribute
        Public Sub New()
        End Sub
        Public Sub New(Comment As String)
        End Sub
    End Class
    
    0 讨论(0)
提交回复
热议问题