Is there a way to make Code Analysis ignore “InternalsVisibleTo”?

情到浓时终转凉″ 提交于 2019-12-11 02:36:17

问题


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?


回答1:


Try this:

#ifdef CODE_ANALYSIS
#else
[InternalsVisibleTo(...)]
#endif


来源:https://stackoverflow.com/questions/19404136/is-there-a-way-to-make-code-analysis-ignore-internalsvisibleto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!