Private methods using .NET reflection. What for?

I have used reflection in public methods many times, but I never realized that private methods can also be called. See Reflection with private members .

Why is this allowed in the first place? Wouldn't that break the rule of "private" as "private"?

+3
source share
5 answers

privatein C #, it really is only part of the language specification; in C #, as well as in Visual Basic or any other reasonable .NET language (including CIL , which is all .NET compile to languages) one of them is not allowed to access private(or protected, if you are not in a derived class) a member in language . However, just because the language does not support public access to members privateor protecteddoes not mean the underlying infrastructure cannot provide access to these members.

, , private protected, . , private protected; , , , , . - , - , , .

+3

, ( ). MethodAccessException.

- ​​ , . . " " , .

+3

, . , - .

slllloooow, , , .

, , !

+1

, . , .

, :

  • . , , . , , .
  • . ​​ , - . private invoke, .

, , , , .

+1

- .NET, .

:

  • ( ) , ReflectionPermission. ( , , .)

  • .

:

  • ( ). , , , , , .

  • , ( , ). , .

, - :

  • , (, , ). - .

  • . .

, . - " Microsoft Visual Basic 2005: ".

+1
source

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


All Articles