c# assembly, friend assembly

本小妞迷上赌 提交于 2020-12-12 13:23:28

问题


The definition for C# internal access modifier is internal: Accessible only within containing assembly or friend assemblies. So my question is what is c# assembly? what does it mean to be within containing assembly or friend assemblies? Does it mean within same namespace or project?


回答1:


An assembly is (in general) a single .dll or .exe file.
A C# project (in general) compiles to a single assembly.

You can mark a friend assembly using the [assembly: InternalsVisibleTo(...)] attribute.




回答2:


You define it using the InteralsVisibleToAttribute.




回答3:


The assembly is IL code with manifest information (in case of .NET), which can be DLL or EXE. In this way, using a manifest information, one assembly can be declared as a friend of another one, so access internal dataypes too.

By using attribute [assembly: InternalsVisibleTo..] you mark into the manifest of the assembly specified information,




回答4:


The assembly contains the intermediate code, resources, and the metadata for itself. We can have a look inside the assembly using the ildasm (Intermediate Language Disassembler) tool that comes as part of Visual Studio. To access it you need to open the Visual Studio Command Prompt and type ildasm.exe. This will launch a Windows application that you can use to explore any .Net application.

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. This is especially convenient in the following scenarios:

  • During unit testing, when test code runs in a separate assembly but requires access to members in the assembly being tested that are marked as Friend (Visual Basic) or internal (C#).

  • When you are developing a class library and additions to the library are contained in separate assemblies but require access to members in existing assemblies that are marked as Friend (Visual Basic) or internal (C#).



来源:https://stackoverflow.com/questions/10484429/c-sharp-assembly-friend-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!