在一个团队或者公司中,一个人开发出来的程序集中的类的可见性有public,private和internal,
public:对所有程序集可见,就是说如果拿到程序集.DLL文件,那么类就被公开了。
private:对程序集内部可见,就是自己定义来自己用,不公开。
internal:对友元程序集和内部可见,是我的朋友才能用这个类。
好了,如果一个程序集中要调用另外一个程序集,但是要被调用的那个程序集又不想用public来公开自己的类,那么怎么办,就是用最后一种internal来用来做类的可见性了。并且声明需要公开出去的友元程序集。
下面看demo:
internal class MyClassInB
{
}
A中引用B~~!然后A要调用B中的MyClassInB类,看看:
好了,程序集开始交朋友了,交朋友有两种方式:
2.在AssemblyInfo.cs里面添加一条:[assembly:InternalsVisibleTo("A")]
在看看结果:
OK了