【问题标题】:How can I specify a column using a #line directive?如何使用#line 指令指定列?
【发布时间】:2012-09-26 21:11:09
【问题描述】:

在 C# 中,您可以在生成的代码中使用 #line 指令来更改错误报告方式和调试方式。

例如,这个剃须刀代码:

@model Foo
@{
    var foo = ViewBag.Foo;
}

可以像这样生成 #line 指令:

#line 2 "project\foo.cshtml"
    var foo = ViewBag.Foo;
#line hidden

但是,当两个 C# 表达式位于同一行时,这种情况就会出现问题,如下所示:

<img width="@width" height="@height" />

像这样生成#line 指令:

#line 40
width
#line hidden
...
#line 40
height
#line hidden

如何在行指令中指定列?

【问题讨论】:

    标签: c# code-generation dsl


    【解决方案1】:

    这是我想出的窍门:

    用空格填充您的代码,以便列对齐,所以

    <img width="@width" height="@height" />
    

    变成

    #line 40
                 width
    #line hidden
    ...
    #line 40
                                 height
    #line hidden
    

    此技巧适用于编译器错误和 Visual Studio 中的调试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 2014-03-08
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多