Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an internal class become private when merged with tools like ILMerge or SmartAssembly?

Lately I found a few tools that allow the .Net Library to be merged within the windows application.

Now the real question is how does the behavior of the library changes,

  1. Does the internal class remain internal to library? Or does it become internal to the application it's been merged with?
  2. Are there chances that library will malfunction?

Extending question:

  1. Won't it be better that when merging the assembly that are internal should be made private so that that can't be used by the application they are merged in?
like image 613
Parimal Raj Avatar asked Feb 19 '23 01:02

Parimal Raj


1 Answers

Classes can't be private unless they're nested.

But consider this: if you're merging assemblies A and B, then you must have already compiled them before merging. When they were compiled, the internal methods of each were inaccessible to the other. Therefore, in the merged code, there could be no method that calls internal methods of the other assembly.

Wont it be better that when merging the assembly that are internal should be made private so that that cant be used by the application they are merged in?

How would that work? If a top-level type were private, it would be accessible to no other types at all. That's why you can't define private types (unless they're nested within another type).

Suppose assembly A has classes C and D, where C is internal, and D calls some method from class C. When class C is made private (in some hypothetical version of the CTS where this is possible), class D breaks.

like image 125
phoog Avatar answered Feb 20 '23 20:02

phoog