隐藏用于帮助测试.NET程序集的公共方法 [英] Hide public method used to help test a .NET assembly

查看:167
本文介绍了隐藏用于帮助测试.NET程序集的公共方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET程序集,被释放。它的发布版本包括:

I have a .NET assembly, to be released. Its release build includes:

  • 在公共,哪个人都应该使用方法说明的API
  • 的其他方法,它存在只是为了帮助测试集,人们不应该使用公共但是未公开的API

要被释放的组件是一个自定义的控制,而不是应用程序。回归测试它,我在一个测试框架/应用,它使用(除了公共/记录的API),其从控制导出的一些先进/未记录的方法运行。

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.

有关,我不希望人们使用公共的方法,我使用了&LT排除它们从文档生成器),和 [EditorBrowsable] 属性,例如像这样的:

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 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);

这成功地将删除API文档的方法,并从智能感知。但是,如果在一个示例应用程序我对接口的实例右键单击以查看其在元数据定义,我仍然可以看到该方法,而 [EditorBrowsable] 属性以及,例如:

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 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);

问题:

  • 有没有一种方法来隐藏一个公共方法,甚至从元数据?
  • 如果没有则相反,对于这种情况,你会建议将这些方法内部和使用 InternalsVisibleTo 属性?或者你会推荐一些其他的方式,如果有什么,为什么?
  • 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?

感谢你。

推荐答案

这两种可能性是 InternalsVisibleTo ,和/或反射。我不知道有任何强有力的理由$ P $过这个想法pfering之一。

The two possibilities are InternalsVisibleTo, and/or reflection. I'm not aware of any strong reason for prefering one over the idea.

这篇关于隐藏用于帮助测试.NET程序集的公共方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆