7

可以[assembly: InternalsVisibleTo("NameOfOtherAssembly")]在 AssemblyInfo.cs 中指定。

但是是否可以将其限制为特定的内部功能?

是否有可以应用于每个功能的属性?

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

internal void ShouldNotBeVisible()
{}

如果没有,还有其他方法可以做到这一点吗?

4

1 回答 1

-1
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.

您可以在源代码文件的开头添加该属性。您不能用它标记单个方法,请参阅MSDN - 文档

如果要拆分类的可见和不可见方法,可以执行以下操作:

在一个文件中,定义您的可见方法并将文件标记为可见:

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

在另一个文件中,定义您的不可见方法:

public partial class Foo
{
  internal void IsNotVisible(){}
}
于 2014-04-07T08:58:07.560 回答