C # Friend Assembly

Source: Internet
Author: User

In team development, if an assembly is to invoke another assembly, but the assembly to be called does not want to expose its own class with public,

So what to do, is to use the last kind of internal to do the visibility of the class.

Here's a simple example:

1. Create two class library projects A and B in one solution, and create classes ClassA and CLASSB in two class library projects, respectively

2. Set the access level of CLASSB in Project B to internal

3. Add a reference to Project B in Project A

4. CLASSB is not accessible in ClassA at this time, and if you want ClassA to have access to CLASSB, you must add the assembly for project A as a friend assembly for the project B assembly. Add friend assembly We want to use the Internalisvisibleto attribute, which requires adding a namespace

Using System.Runtime.CompilerServices.

5. Use the Internalisvisibleto attribute in the ClassB class to add assembly TA as a friend assembly.

6. The Internalisvisibleto feature can also be added to the AssemblyInfo.cs.

7. The CLASSB of Project B can now be accessed in ClassA, Project A.

C # Friend Assembly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.