Monday, May 22, 2006

Friend Assemblies

I havent been able to blog, because the internet connection at my place is screwed up. The BT line has been disconnected. And i am not allowed to access blogspot at my workplace.
Recently i worked with friend assemblies in .NET framework 2.0. In some cases we need to limit the use of some classes to the assemblies in wihch they are defined. The "internal" keyword in C# allows us to do that. It hides the specification of these classes even when you refer these assemblies in a project.
But in some cases we might need to use these classes in some other assemblies. But on the other hand we do not want to declare these classes as public. here comes the sweet part of the .NET framework. We can use the "InternalsVisibleToAttribute" to specify as to which assemblies can use the internal classes.


The usage would be something like:

[assembly:InternalsVisibleToAttribute("MyFriendAssembly”)]

This attribute when applied to an assembly indicates that all internal types in that assembly would be visible to another assembly, whose name is specified in the attribute constructor.

2 comments:

  1. Got a response before I could finish my sandwich. Apply online for credit cards here and get approved very fast, just like me.

    ReplyDelete