如何使用 Visual Studio 在源代码文件中查找匿名类型

发布于 2024-12-06 13:53:44 字数 572 浏览 0 评论 0原文

在混淆 .NET 程序集(使用 Dotfuscator)的过程中,我发现自己正在调整事物的重命名方式。这通常涉及查看 ILDASM 中的程序集并将类型追溯到定义它的源代码文件。

通常这是一个简单的过程。但我发现定位匿名类型非常困难——尤其是在大型程序集中。

如果我尝试查找匿名类型的位置,例如以下代码行:

new { Name = 'Gene', Age = 30 }

其编译为:

<>f__AnonymousType0`2'<'<Name>j__TPar','<Age>j__TPar'>`

并显示为 ILDASM 树中程序集的根。

如果我想在源代码中找到匿名类型,我将没有太多帮助:

  • 没有命名空间
  • 没有可搜索的符号
  • 解决方案导航器中没有任何内容
  • 类视图中没有任何
  • 内容 对象浏览器中没有任何

内容 我是否遗漏了什么?是否有任何工具可以帮助在代码文件中查找匿名类型?

During the process of obfuscating a .NET assembly (using Dotfuscator), I have found myself tweaking how things are renamed. This often involves looking at the assembly in ILDASM and tracing a Type back to the source code file that it is defined in.

Usually this is a simple process. But I have found that locating an Anonymous Type is very difficult -- especially in a large assembly.

If I am trying to find the location of an anonymous type, such as the following line of code:

new { Name = 'Gene', Age = 30 }

Which is compiled as:

<>f__AnonymousType0`2'<'<Name>j__TPar','<Age>j__TPar'>`

And appears as the root of the assembly in the ILDASM tree.

If I want to locate the anonymous type in the source code, I am left without much help:

  • No Namespace
  • No symbols to search on
  • Nothing in the Solution Navigator
  • Nothing in the Class View
  • Nothing in the Object Browser

Am I missing something? Are there any tools to help locate an Anonymous Type in code files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雄赳赳气昂昂 2024-12-13 13:53:44

显然,匿名类本身的代码不存在于原始源代码中,但是有源代码导致匿名类的创建,我认为这就是您想要找到的内容。但是,可能涉及多个源文件。

例如,在您的示例中,可能存在:

Class1.cs:
    var x = new { Name = "Jon", Age = 10 };

Class2.cs:
    var y = new { Name = 100, Age = 10m };

// And potentially many other source files

两者都将使用相同的泛型类型,但具有不同的类型参数。基本上,您需要以相同的顺序使用相同的属性名称来查找每个anonymous-object-creation-expression表达式。如果元数据不包含任何可以直接帮助您的内容,我不会感到惊讶。

编辑:当然,生成的代码将包含对匿名类型的构造函数的引用 - 所以您可以查找它。目前尚不清楚您正在使用什么工具,但在 IL 中搜索匿名类型的名称将有助于使用。

Obviously the code for the anonymous class itself isn't present in the original source code, but there's source code which leads to the creation of the anonymous class, and I assume that's what you're trying to find. However, There may be multiple source files involved.

For example, in your example, there could be:

Class1.cs:
    var x = new { Name = "Jon", Age = 10 };

Class2.cs:
    var y = new { Name = 100, Age = 10m };

// And potentially many other source files

Both of those would use the same generic type, but with different type arguments. Basically you'd need to find every anonymous-object-creation-expression expression using the same property names in the same order. I wouldn't be surprised if the metadata contained nothing to help you here directly.

EDIT: The generated code will contain a reference to the constructor of the anonymous type, of course - so you could look for that. It's not clear what tools you're using, but searching for the name of the anonymous type within the IL would fine the uses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文