Hide public method used to help test a .NET assembly
- by ChrisW
I have a .NET assembly, to be released. Its release build includes:
A public, documented API of methods which people are supposed to use
A public but undocumented API of other methods, which exist only in order to help test the assembly, and which people are not supposed to use
The assembly to be released is a custom control, not an application. To regression-test it, I run it in a testing framework/application, which uses (in addition to the public/documented API) some advanced/undocumented methods which are exported from the control.
For the public methods which I don't want people to use, I excluded them from the documentation using the <exclude> tag (supported by the Sandcastle Help File Builder), and the [EditorBrowsable] attribute, for example like this:
/// <summary>
/// Gets a <see cref="IEditorTransaction"/> instance, which helps
/// to combine several DOM edits into a single transaction, which
/// can be undone and redone as if they were a single, atomic operation.
/// </summary>
/// <returns>A <see cref="IEditorTransaction"/> instance.</returns>
IEditorTransaction createEditorTransaction();
/// <exclude/>
[EditorBrowsable(EditorBrowsableState.Never)]
void debugDumpBlocks(TextWriter output);
This successfully removes the method from the API documentation, and from Intellisense. However, if in a sample application program I right-click on an instance of the interface to see its definition in the metadata, I can still see the method, and the [EditorBrowsable] attribute as well, for example:
// Summary:
// Gets a ModelText.ModelDom.Nodes.IEditorTransaction instance, which helps
// to combine several DOM edits into a single transaction, which can be undone
// and redone as if they were a single, atomic operation.
//
// Returns:
// A ModelText.ModelDom.Nodes.IEditorTransaction instance.
IEditorTransaction createEditorTransaction();
//
[EditorBrowsable(EditorBrowsableState.Never)]
void debugDumpBlocks(TextWriter output);
Questions:
Is there a way to hide a public method, even from the meta data?
If not then instead, for this scenario, would you recommend making the methods internal and using the InternalsVisibleTo attribute? Or would you recommend some other way, and if so what and why?
Thank you.