如何在 C# 中使用 .cshtml 和其他文件类型作为字符串来构建开发人员文档

how to use .cshtml and other file types as a string in C# for building developer documentation

如何在 C#/Razor 中渲染 .cshtml.scss.ts 等文件以用于文档?

为清楚起见,我正在寻找类似以下内容的内容:

<section>
   <pre>
      @SomeWayToShow("~/path/to/accordian-tabs.cshtml")
   </pre>
   <pre>
      @SomeWayToShow("~/path/to/_accordian-tabs.scss")
   </pre>
   <pre>
      @SomeWayToShow("~/path/to/accordian-tabs.ts")
   </pre>
</section>

这里有一个来自 bourbon.io 的例子作为最终目标的例子。

您可以尝试使用 function 块,例如:

@functions {

   string SomeWayToShow(string path)
   {
       var filePath = System.Web.HttpContext.Current.Server.MapPath(path);

       if (System.IO.File.Exists(filePath))
          return System.IO.File.ReadlAllText(filePath);

       return string.Empty;
   }

}

如果可以帮助您在 path 参数中提供给定文件的内容。要对其进行格式化,您应该查看一些组件以突出显示结果。