mercredi 9 septembre 2020

Using Reflection for Private fields

I was earching around the web for SF fields in unity . I wanted to know what exactly the attribute SF did in unity .After couple of reads I ended up knowing a new information . It is about Reflection . Turns out that , using Reflection you can actually end up getting the information of the class ( I know this isn't anything new yet ) . However the Information that you can gather was a bit obscure for me . If I understood correctly , using Reflection you can get to the private fields and methods of a Class . My question now , knowing the fact that private fields can be accessed even outside of a Class itself is , why do we use private fields in general ? I always thought these fields were for security risks and touching stuff like :PASSWORD: would be bad if it is not in the class that we want to handle the login logic , for example . But if you can use Reflection to get everything , what is the difference now between private and public ? This concept is very new and interesting to me (Reflection) and I would highly appreciate an adequate answer , with examples . Thank you in advance !





Aucun commentaire:

Enregistrer un commentaire