当应[总成:InternalsVisibleTo()]中使用? [英] When should [assembly: InternalsVisibleTo()] be used?

查看:140
本文介绍了当应[总成:InternalsVisibleTo()]中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知, InternalVisibleTo 的属性是用来揭露类型和方法与内部访问修饰符到一个指定的程序集。我只用过这个曝光的内部方法包含一套单元测试一个单独的程序。

I understand that the InternalVisibleTo attribute is used to expose types and methods with the internal access modifier to a specified assembly. I have only ever used this for exposing internal methods to a separate assembly containing a suite of unit tests.

我奋力想另一种情况时,这应该被使用。当时这个属性推出的专门帮助单元测试或者是有其他的原因?

I am struggling to think of another scenario when this should be used. Was this attribute introduced specifically to aid unit testing or was there another reason?

推荐答案

一个场景是,你有逻辑组件之间的分离(如内部数据对象和逻辑层)。你不希望将类暴露给用户,但你仍然要使用的对象在自己的组件。

A scenario can be that you have separation of logic between assemblies (like internal data objects and the logic layer). You don't want to expose the classes to your users, but you still want to use the objects in your own assemblies.

我觉得这不是一个很常见的场景,我很少使用的 InternalsVisibleTo 的非单元测试环境。

I think this is not a very common scenario, I hardly ever use InternalsVisibleTo in non unit tests context.

这篇关于当应[总成:InternalsVisibleTo()]中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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