Domanda

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?

È stato utile?

Soluzione

Try this:

#ifdef CODE_ANALYSIS
#else
[InternalsVisibleTo(...)]
#endif
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top