任何使 GetTypes() 不那么脆弱的方法

发布于 2024-09-02 22:45:46 字数 467 浏览 1 评论 0原文

我正在迭代 GAC、GAC_32 和 GAC_MSIL 中的所有类型,寻找特定类型,从根本上匹配源代码中的那些 using 子句,因此当我编译源代码时。我会确切地知道要提供什么程序集 dll。

我从每个目录中获取所有文件名,并将 GetTypes 应用于每个目录 依次组装并将返回的类型与我的使用列表进行比较。但问题我 问题是,当 GetTypes() 无法加载类型时,它会不断地抛出异常 来自加载的程序集。

他们有什么办法可以让 GetTypes() 不那么脆弱吗?例如,当在我的盒子上解析此程序集 {blbmmc, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35} 时,它会崩溃。

欢迎任何建议。

我知道这是一个相当漫长的过程,但我想我最终将使用公共程序集的子集来搜索,或者可能在程序启动时缓存类型列表 - >程序集 dll 名称。

谢谢。

I'm iterating through all the types in GAC, GAC_32 and GAC_MSIL looking for specific types, fundamentally to match those using clauses in my source code, so when I compile the source. I'll know exactly what assembly dll's to provide.

I'm getting all the file names from each of those directory and applying GetTypes to each
assembly in turn and comparing the returned types against my using list. But the problem I
have is that GetTypes() keeps crapping out with an exception, when it can't load the types
from a loaded assembly.

Is their any way to make GetTypes() less brittle. For instance, when parsing this assembly on my box, {blbmmc, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}, it craps out.

Any suggestions welcome.

I know this is a fairly lengthly process, but I figure i'll eventually use a subset of common assemblies to search, or possibly cache the list of types->assembly dll name at program start.

Thanks.

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

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

发布评论

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

评论(1

白芷 2024-09-09 22:45:47

继续我原来的评论,我建议您列出实际需要的程序集,而不是搜索它们。

另外,在代码生成的上下文中,我不知道您的任务范围,但我发现非常方便 在我的项目中使用 CodeDOM

但对于像“动态创建方法”这样的任务 表达式树太棒了。 (特别是在 .NET 4.0 中)

Continuing with my original comment, I would recommend to have a list of assemblies you actually need rather than searching for them.

Also, in the context of code generation, I don't know the scope of your task, but I found quite convenient using the CodeDOM for my projects when I needed classes generated from specific XML Schema.

But for tasks like 'create a method on the fly' Expression Trees are just awesome. (Especially in .NET 4.0)

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