Reg: Reflection accessing private Memebers..
-
Hi CLRers, I have one doubt regarding usage of the reflection to get the private member variables. In one of my assembly through reflection i am getting private member variables in the same assembly classes.Client can change the Code Access policy to restrict the private member variable right? Client can only restrict to accessing only private members or any members can restrict?. if yes than what is the use of reflection... So usage of reflection in projects how much safe .......? and Reflection is usefull in Unit test drivers only or wht? Please help in this regard .... Urs .. Kiran Kumar Singani The Dream is not what you see in sleep........Dream is the thing which does not let you sleep
-
Hi CLRers, I have one doubt regarding usage of the reflection to get the private member variables. In one of my assembly through reflection i am getting private member variables in the same assembly classes.Client can change the Code Access policy to restrict the private member variable right? Client can only restrict to accessing only private members or any members can restrict?. if yes than what is the use of reflection... So usage of reflection in projects how much safe .......? and Reflection is usefull in Unit test drivers only or wht? Please help in this regard .... Urs .. Kiran Kumar Singani The Dream is not what you see in sleep........Dream is the thing which does not let you sleep
-
Still it is not answered my question... Through reflection how much safe to access private members ? It is violating OOPs concepts.. Regards, Kiran Kumar Singani
-
Still it is not answered my question... Through reflection how much safe to access private members ? It is violating OOPs concepts.. Regards, Kiran Kumar Singani
It is not safe because you try to access methods at run time using "reflection". Use SecurityPermissionAttributes on your private methods for which you want to access. What is the reason behind accessing a private mthod. Do it public then. As a design rule, make things non-punlic if you don't neeed them or if you want to secure them. Have alook at .NET Reflector tool which disassembles any .NET assembly to it's original source code using reflection including of course the private ones. Which means you can access but this tool also shows how unsecure your private methods are. To call these methods, I've not tried actually but as I said, try to make them internal or private and add SecurityAttributes to ptotect. Hope this helps...