By defining a class as internal, you define what will usually be public fields as internal?

When defining a class as internal, you define how public fields will usually be as internal? Or will you leave them public? I have a set of classes with public / private methods that I decided to set as internal. Now, should I change the class modifier to internal and leave the remaining methods / properties as they are (public / private) or switch them to (internal / private)?

I don’t see much point in changing it to internal, and if for some reason I want to return them to the public later, it will give a lot of work to send them back for publication.

Any other thoughts on this?

+3
source share
6 answers

I see no reason not to leave them public, since your class will not be visible to external assemblies. The only time I think it can make a difference is to use reflection on this class.

+6
source

If I have an inner class, I leave the members of the class public (or protected / private, of course, if they are). I find that often I have classes that I hope I can keep internal, that I ultimately have to expose and switch all relevant members to the public, which is annoying.

+2
source

, . , .

+1

, , , Type .

, , API, , , , "", .

, , - .

, - , , , ( ) .

+1

, . , , . , .

0

Reflector , , BCL . public internal. , .

"" , , , :

  • internal , . , , ( Dispose IDisposable ), .

  • . , internal , . , . , , .

  • , , internal public, - , . internal , , protected internal , , .

, , , . internal :

  • , . , 5 . , , - public, / , . , public.

  • It is truly unsafe for external consumption; it can manipulate any protected state, open descriptors or transactions, etc. In this case, you really want to make separate methods internalso that they absolutely understand that no one should use this class.

Choose the one that suits your scenario.

0
source

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


All Articles