问题描述
我们有很多包含内部类的程序集,这些内部类通过使用 InternalsVisibleTo
使内部类对单元测试程序可见。 >
这很好用,但是问题是,一旦您使用 InternalsVisibleTo
,它就会阻止代码分析CA1812警告(避免未实例化的内部类)。
它还可以防止CA1811:避免未调用的私有代码。
我进行了一些调查,发现很多未使用的内部类因此而未被警告。
目前,我的解决方案是手动编辑每个程序集中的 AssemblyInfo.cs文件,以暂时注释掉 InternalsVisibleTo
,以便我可以编译该项目并发现没用过的内部类。
这是一个巨大的麻烦,当然,如果这样的事情没有自动完成,它通常会
一个解决方案是能够告诉代码分析忽略 InternalsVisibleTo
属性。
有人知道是否存在这种可能性吗?
尝试一下:
#ifdef CODE_ANALYSIS
#else
[InternalsVisibleTo(...)]
#endif
We have a lot of assemblies that contain internal classes which we are unit-testing by using InternalsVisibleTo
to make the internal classes visible to the Unit Test assembly.
This works fine, but the problem is that as soon as you use InternalsVisibleTo
, it prevents the Code Analysis CA1812 warning (Avoid uninstantiated internal classes).
It also prevents CA1811: "Avoid uncalled private code".
I've done some investigation, and I've found quite a lot of unused internal classes that we weren't being warned about because of this.
My solution for the moment is to hand-edit the "AssemblyInfo.cs" file in each assembly to temporarily comment-out the InternalsVisibleTo
so that I can compile just that project and discover unused internal classes.
This is a huge hassle, and of course if something like that doesn't get done automatically, it frequently doesn't get done at all.
A solution would be to be able to tell Code Analysis to ignore the InternalsVisibleTo
attribute.
Does anyone know if such a possibility exists?
Try this:
#ifdef CODE_ANALYSIS
#else
[InternalsVisibleTo(...)]
#endif
这篇关于有没有一种方法可以使代码分析忽略“ InternalsVisibleTo”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!