如何从VB.NET项目中移除Codedom生成的代码片段?

2026-05-06 09:131阅读0评论SEO基础
  • 内容介绍
  • 相关推荐

本文共计231个文字,预计阅读时间需要1分钟。

如何从VB.NET项目中移除Codedom生成的代码片段?

要删除由Codedom生成的代码中的特定项,可以通过以下VB.NET代码片段实现:

vbImports System.Text.RegularExpressions

Module Module1 Sub Main() ' 假设这是你的原始代码字符串 Dim originalCode As String='------------------------------------------------------------------------------'+This code was generated' ' 使用正则表达式匹配并删除由Codedom生成的代码注释 Dim regex As New Regex((?<=\n)\s*'+This code was generated') Dim modifiedCode As String=regex.Replace(originalCode, )

' 输出修改后的代码 Console.WriteLine(modifiedCode) End SubEnd Module

有没有办法从VB代码中删除Codedom中生成的代码中的项目?

例如,在我生成的所有代码的顶部,它具有:

'------------------------------------------------------------------------------ ' ' This code was generated by a tool. ' Runtime Version:4.0.30319.1 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' '------------------------------------------------------------------------------ Option Strict Off Option Explicit On

我希望这两个都消失 – 评论文本和选项xxx.我尝试过使用CodeGeneratorOptions,但无法从生成的代码中删除上述内容.

不,那是无法删除的.它被硬编码到VBC编译器中.您可以在Reflector中的system.dll中看到这一点.

如何从VB.NET项目中移除Codedom生成的代码片段?

本文共计231个文字,预计阅读时间需要1分钟。

如何从VB.NET项目中移除Codedom生成的代码片段?

要删除由Codedom生成的代码中的特定项,可以通过以下VB.NET代码片段实现:

vbImports System.Text.RegularExpressions

Module Module1 Sub Main() ' 假设这是你的原始代码字符串 Dim originalCode As String='------------------------------------------------------------------------------'+This code was generated' ' 使用正则表达式匹配并删除由Codedom生成的代码注释 Dim regex As New Regex((?<=\n)\s*'+This code was generated') Dim modifiedCode As String=regex.Replace(originalCode, )

' 输出修改后的代码 Console.WriteLine(modifiedCode) End SubEnd Module

有没有办法从VB代码中删除Codedom中生成的代码中的项目?

例如,在我生成的所有代码的顶部,它具有:

'------------------------------------------------------------------------------ ' ' This code was generated by a tool. ' Runtime Version:4.0.30319.1 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' '------------------------------------------------------------------------------ Option Strict Off Option Explicit On

我希望这两个都消失 – 评论文本和选项xxx.我尝试过使用CodeGeneratorOptions,但无法从生成的代码中删除上述内容.

不,那是无法删除的.它被硬编码到VBC编译器中.您可以在Reflector中的system.dll中看到这一点.

如何从VB.NET项目中移除Codedom生成的代码片段?