Posty

Wyświetlanie postów z luty, 2018

[Part 1] Is c# safe? Are Internal class accessible only from the same assembly?

Obraz
Hi I was wondering for some time about encapsulation in C#. Are internal class accessible only from the same assembly? Are private fields accessible only from inside class? Quoting the Microsoft website: "Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared...." "Internal types or members are accessible only within files in the same assembly..." It looks like true. I believed it, but I decided to check it out. There is a possibility to read and modify private fields and create instances of internal classes when reflection is used. Reflection is the built-in mechanizm allowing to dynamically create instance of class or invoke methods. Unfortunately it allows access to private fields and much more... I wrote a simple example showing how powerful is reflection. Code is uploaded to github.  GITHUB - PrivateFieldsInternalClass My soluti