Make a specific internal function visible to another assembly (i.e. not all visible internal elements)

Can be specified [assembly: InternalsVisibleTo("NameOfOtherAssembly")]in AssemblyInfo.cs.

But can this be limited to specific internal functions?

Is there, for example, an attribute that can be applied to each function?

[InternalVisibleTo("NameOfOtherAssembly")]
internal void ShouldBeVisible()
{}

internal void ShouldNotBeVisible()
{}

If not, is there any other way to do this?

+4
source share
1 answer
The attribute is applied at the assembly level. 
This means that it can be included at the beginning of a source code file, 
or it can be included in the AssemblyInfo file in a Visual Studio project. 
You can use the attribute to specify a single friend assembly that can access 
the internal types and members of the current assembly.

You can add an attribute at the beginning of the source code file . You cannot mark any one method, see MSDN - Documentation .

if you want to separate the visible and invisible class methods, you can do the following:

:

InternalsVisibleTo("NameOfOtherAssembly")]
public partial class Foo
{
  internal void Visible(){}
}

:

public partial class Foo
{
  internal void IsNotVisible(){}
}
-1

Source: https://habr.com/ru/post/1534684/


All Articles