Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of Java's default (package) access in C#?

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?

The Problem:

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?

like image 437
Nosrama Avatar asked Aug 25 '09 18:08

Nosrama


2 Answers

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

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.

like image 166
LBushkin Avatar answered Nov 15 '22 19:11

LBushkin


There's nothing that's an exact equivalent. The internal keyword is close, but it limits by assembly, not by namespace.

If something is tagged with internal, it can only be accessed by code within the same assembly (dll, exe)

like image 36
Brad Cupit Avatar answered Nov 15 '22 21:11

Brad Cupit