InternalsVisibleTo

Just a quick tip.  Every once in a while, you’ll need to share code between specific assemblies, and only those assemblies.  A common example is when you want to strap a test-harness to an object, but not publicly expose the type.

/// <summary>
/// Vital component.
/// </summary>
/// <remarks>
/// Ensure stability but don't publicly expose.
/// </remarks>
internal static class CriticalComponent
{
}

Sometimes you just need to expose an object, type, or method to another specific assembly.  Fortunately, you can!

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
 
// Allow ExampleAssembly.Tests to test internals
[assembly: InternalsVisibleTo("ExampleAssembly.Tests")]
 
// General Information about an assembly is controlled 
// through the following set of attributes. Change 
// these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ExampleAssembly")]

Check out the MSDN for full details.  It’s a handy thing when you need it.  Oh, and remember to put your assembly attributes in your AssemblyInfo file.

Leave a comment