Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reg: Reflection accessing private Memebers..

Reg: Reflection accessing private Memebers..

Scheduled Pinned Locked Moved C#
questiontestinghelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kiran Kumar Singani
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • K Kiran Kumar Singani

      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

      A Offline
      A Offline
      AFSEKI
      wrote on last edited by
      #2

      Have look at NUnit source code ;)

      K 1 Reply Last reply
      0
      • A AFSEKI

        Have look at NUnit source code ;)

        K Offline
        K Offline
        Kiran Kumar Singani
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • K 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

          A Offline
          A Offline
          AFSEKI
          wrote on last edited by
          #4

          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...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups