I'd like to declare some members of a module accessible to an entire namespace, but have them not be accessible from without.
Is this possible?
Thanks.
I'd like to declare some members of a module accessible to an entire namespace, but have them not be accessible from without.
Is this possible?
Thanks.
No, there is only the internal accessibility that limits access to your current Assembly.
Since your post has the VB.NET tag: internal is a c# keyword, it's equivalent in VB is friend:
With the hole list being:
(apologies for the C# terminology/examples...)
No. You can restrict :
internal
)[InternalsVisibleTo]
)protected
)(and some combinations, such as protected internal
)
That's about it. Nothing based on the caller's namespace. After all - I can just do this:
namespace Your.Namespace {
public static class MyEvilClass {
public static void DoEvil() {
YourPrivateClass.PushTheRedButton();
}
}
}
and I've broken it...
While there is no compile time support for this you can certainly enforce it at runtime.
new StackTrace().GetFrames()
This will give you the stack trace that you can check to see if the call came from an allowed namespace.
PLEASE DO NOT EVER DO THIS THOUGH. It will certainly make other peoples lives worse.
there is no concept of namespace once your code is compiled to IL. What the compiler see is just a string with dots in the type's name. If you want to restrict the caller to known parties, check the calling assembly's public key and compare to a white list.