Introduction
This is new feature in c# 2.0. Suppose in your assembly some members are inaccessible but u want to access in other assembly of your project for example say enhancement of your project. What you will do? ,Suppose if you make the accessors of members you want to access outside the assembly to public. Then here the problem is that members are accessible in all other assemblies. But you must restrict it what you will do? Here Friend assemblies plays the game .
Let us look an example
All the non-public types in an assembly can be accessed by another assembly, if the first assembly is declared as a "friend" of the second. A friend assembly is declared by using the InternalsVisibleToAttribute class. For example, assume a large project contains two assemblies, A and B. Assembly B needs access to a type contained in assembly A, but this type has been declared as internal to prevent unauthorized use. Assembly A can declare assembly B as a friend, and as such, assembly B can access the non-public types of assembly A as if they were part of the same assembly. Note that this does not mean that assembly A can access types in assembly B. To achieve that, assembly B would also have to define assembly A as a friend assembly. Also, if another assembly, C, is declared a friend of assembly B, and assembly B is a friend of assembly A, assembly C does not automatically become a friend of assembly A.
Summary
This main aim of writing this article is to expose one of the new feature of c#.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|