views:

63

answers:

2

I have a class library assembly and some test code. Because the test code needs to peek at the internals of the the class, it needs to be part of the assembly and because I don't want to have it run all by it's self, it needs have something public so that a different assembly can invoke it. This ends up tacking on some code that shouldn't be there to the main assembly.

What I'd like is to place all the test code in the other assembly and somehow grant it privileges to access internals of the class. I don't need this to be part of the final product, just as part of the debug/private builds.

Is that possible?

+8  A: 

Make liberal use of the internal access modifier and add the InternalsVisibleTo attribute to the assembly.

Joel Coehoorn
Checking now. if that name isn't misleading, that's exactly what I need.
BCS
It's tricky-- you need to sign your other assembly-- but it should work.
Joel Coehoorn
You only need to sign the other assembly if the first assembly is signed. It's a "neither or both" scenario.
Jon Skeet
Of course: missed a "may" in my comment :( Stupid fingers!
Joel Coehoorn
+3  A: 

You want System.Runtime.CompilerServices.InternalsVisibleTo()

You can also use reflection to access internal / private members. This is how MSTest does it.

JoshBerke