开发者

Merging assemblies and using internal keyword

开发者 https://www.devze.com 2023-03-08 04:23 出处:网络
Does merging assemblies change the scope of the internal keyword? I\'m fairly certain that it wouldn\'t have an effect (or at least one that would matter) since anyone referencing the final assembly

Does merging assemblies change the scope of the internal keyword?

I'm fairly certain that it wouldn't have an effect (or at least one that would matter) since anyone referencing the final assembly wouldn't be able to access internal classes anyway.

This might be a hypothetical question with no real world value, but I was curious nontheless.

Edit: I do mean with ILMe开发者_如何学Crge, not combining source code into a single buildable assembly.


Yes once the assemblies are merged, they get access to each others internal classes. This is specifically leveraged by some obfuscators to make public calls between assemblies into internal calls and then obfuscate them making it more secure. Reference: SmartAssembly

On a side note, using ILMerge, you can use the /internalize command line switch which will make all public classes in assemblies other than the primary assembly internal, which removes public interfaces from the end-user's eye but still the assemblies function normally.


Assuming you are not running with full-trust , any types that were merged into the final assembly with the internal types would now be able to access the public members of the internal types.

So given assembly A:

public class MyClassA { ... }

and assembly B:

internal class MyClassB { ... }

MyClassA may not have permission to reflect the public members of MyClassB. If they were merged into the same assembly, then MyClassA may gain such a permission.


Another possible resource for more info is Microsoft Research's ILMerge page, where they offer an alternative to ILMerge

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号