gpt4 book ai didi

c# - 仅获取程序集中定义的类型

转载 作者:行者123 更新时间:2023-11-30 13:48:21 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How to prevent ReflectionTypeLoadException when calling Assembly.GetTypes()

我想获取程序集中的所有类型。但是,我收到以下错误:

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.

问题是我从中获取类型的程序集引用了另一个仅在生产环境中可用的程序集,而不是在单元测试环境中。

那么,有什么方法可以过滤 GetTypes 或类似的东西,只返回程序集中实际定义的类型,而不获取类型加载异常?

例如替换为

.Assembly.GetTypes().Where(t => t.Namespace.Equals(...

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com