默认情况下,程序集中的类(在我的例子中是 DelegatesSampleApplication)是内部的。因此,外部程序集不应该能够正确访问它们,除非它们被声明为该特定程序集的友元程序集? 现在,在另一个程序中,这对我来说绝对是一个不同的程序集(在我的例子中是 ReflectionSampleApplication),我尝试通过反射 Assembly.LoadFrom 加载该程序集。现在我可以访问该程序集所谓的“内部”类中的类型对象。 这是预期的行为吗?我错过了什么吗?
最佳答案
And I am now able to access the type objects within the so called "Internal" classes of that assembly. Is that an expected behaviour ?
是的,这是预期的。
Am I missing something ?
访问修饰符用于控制“正常”编译代码中的访问。它们从来就不是为了限制 Reflection。它们与任何安全或保密无关,它们是为了帮助组织您的代码。
关于c# - C# 中的访问级别修饰符与程序集加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32155239/