Making internal methods visible

I got to learn some Assembly goodness recently. It used to be a pain for me to add internal methods to a class because it meant that testing them wouldn’t necessarily be trivial. You’d have to exercise the public method(s) that calls it to test it….assuming there is one. As I believe in TDD and in my “Can’t test it, don’t write it” policy, I rarely used internal methods…until now 🙂

As it turned out, it is feasible to allow access to the internals of a project to another project (preferably your test project). You only need to modify the Assembly.cs file of the project whose internals you want to expose. Just add the line below:


[assembly: InternalsVisibleTo("The Assembly Name of the other project, PublicKey=the public token of the other project")]

Advertisements
Making internal methods visible

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s