Namespace-only class visibility in C#/.NET?

You can make the classes internal but this only prevents anyone outside of the assembly from using the class. But you still have to make a separate assembly for each namespace that you want to do this with. I’m assuming that is why you wouldn’t want to do it.

Getting the C# Compiler to Enforce Namespace Visibility

There is an article here (Namespace visibility in C#) that shows a method of using partial classes as a form of “fake namespace” that you might find helpful.

The author points out that this doesn’t work perfectly and he discusses the shortcomings. The main problem is that C# designers designed C# not to work this way. This deviates heavily from expected coding practices in C#/.NET, which is one of the .NET Frameworks greatest advantages.

It’s a neat trick… now don’t do it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)