C#中Java的默认(包)访问权限等效于什么? [英] What is the equivalent of Java's default (package) access in C#?

查看:113
本文介绍了C#中Java的默认(包)访问权限等效于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,Java的默认(包)访问权限等同于什么?有一个吗?反正有限制访问特定名称空间的权限吗?

What is the equivalent of Java's default (package) access in C#? Is there one? Is there anyway to restrict access to a particular namespace?

问题:

我试图将对某些方法的访问限制在我的NUnit测试中-在JUnit中,我将通过对方法包进行访问并将测试放在同一个包中但在src / test / java而不是src / main /下的方式来实现Java的

I'm trying to restrict access to certain methods to just my NUnit tests - in JUnit I would do this by making the methods package access and having the test in the same package but under src/test/java instead of src/main/java. How can I achieve something similar in C#?

注意:由于测试,我无法将方法设为内部

Note: I can't make the methods internal because my tests are in a separate assembly - as is the NUnit convention - or is it?

推荐答案

C#没有包或名称空间级别的访问权限? -仅程序集级别-也称为内部访问。

C# does not have package or namespace level access - only assembly level - which is also known as internal access.

但是,您可以将方法设置为内部方法,并使用 InternalsVisibleTo 属性可将其公开给您的单元测试程序集。

However, you can make your methods internal and use the InternalsVisibleTo attribute to expose them to your unit test assembly.

您可能会发现阅读这篇文章和这个

You may find it useful to read this post and this one.

这篇关于C#中Java的默认(包)访问权限等效于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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