Read the Classics-"CLR via C #" (Jeffrey Richter) Note _ Friend assembly

Source: Internet
Author: User

"Application Scenario"

Assembly A accesses the members of the class that are defined by Assembly b for the Internal access type.

"How to use"

When building Assembly B , introduce System.Runtime.CompilerServicesto add InternalsVisibleTo attribute

Example

Assembly b--

using System; using System.Runtime.CompilerServices; // for InternalsVisibleTo Properties // the internal types in the current assembly can be set by the following assemblies // any code access (no matter what version or language culture) [Assembly:internalsvisibleto (" Assembly A's name, publickey=1234 ... " )]internalsealedclass someinternaltype{...}

Assembly a--

using System; Internal Sealed class Foo {  privatestatic  Object SomeMethod () {    //  This assembly a can access the internal type in another assembly    ,// as if it were a public type    new  Someinternaltype ();     return sit;  }}

Note

Do not specify a version number when adding InternalsVisibleTo attribute, language culture and processor architecture

Read Classics-CLR via C # (Jeffrey Richter) Notes _ Friend Assemblies

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.