Reputation: 27783
I remember reading briefly that you can add assembly attributes so that you can only allow specific assemblies to call into an assembly. But I can't remember where I saw that or how to do it - can someone point me in the right direction?
Just to be clear, this question is asking:
Upvotes: 4
Views: 577
Reputation: 3892
I don't think there is any attribute you could be set to restrict access.
I used this link as a reference.
http://msdn.microsoft.com/en-us/library/4w8c1y2s(v=vs.71).aspx
For the DLL code itself, try using internal to mark items that only the assembly can access. For items truly accessible to the outside world, mark as public.
Upvotes: 0
Reputation: 4012
There are no such assembly attributes, there is only one assembly attribute related to the type visibility which grants access to assembly internals by other assemblies - InternalsVisibleToAttribute.
Upvotes: 0
Reputation: 6453
Friend Assemblies are what you're looking for:
A friend assembly is an assembly that can access another assembly's Friend (Visual Basic) or internal (C#) types and members. If you identify an assembly as a friend assembly, you no longer have to mark types and members as public in order for them to be accessed by other assemblies.
Upvotes: 1
Reputation: 217293
You can use the InternalsVisibleTo Attribute to allow assemblies referencing your assembly to see classes and members marked as internal
. I believe there is no way to prevent an assembly to reference your assembly and access all public
classes and members.
Note: using reflection, any assembly can access any class or member, regardless of whether that is public
or internal
(or private
), provided the application is running with Full Trust (which is usually the case).
Upvotes: 4