Hiding Attributes from Reflection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sascha Dietl

    Hiding Attributes from Reflection

    Hi NG,
    is there any way to hide an attribute from being reflected through PropertyInfo?
    The reason for that question: I got a class with a lot of attributes which
    are public and bound to the instance and I want to expose a few to an user
    interface but even not all.

    thanks for any help

    regards
    sascha


  • Jon Skeet [C# MVP]

    #2
    Re: Hiding Attributes from Reflection

    Sascha Dietl <gidror@web.dew rote:
    is there any way to hide an attribute from being reflected through PropertyInfo?
    The reason for that question: I got a class with a lot of attributes which
    are public and bound to the instance and I want to expose a few to an user
    interface but even not all.
    Could you clarify whether you're really talking about attributes, or
    whether you're really talking about properties?

    Do you have control over the user interface in question, by the way?

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • Sascha Dietl

      #3
      Re: Hiding Attributes from Reflection

      Hello Jon,
      Do you have control over the user interface in question, by the way?
      i'm sorry my mistake i meant properties that i want to hide from reflection.

      regards
      Sascha


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Hiding Attributes from Reflection

        Sascha Dietl <SaschaDietl@di scussions.micro soft.comwrote:
        Do you have control over the user interface in question, by the way?
        >
        i'm sorry my mistake i meant properties that i want to hide from reflection.
        Okay, no problem. You can't prevent the properties from being available
        from reflection, but if you apply [Browsable(false )] to the property,
        then the normal visual designers won't display the property. Depending
        on what UI is displaying the objects, that may be good enough.

        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        • Marc Gravell

          #5
          Re: Hiding Attributes from Reflection

          Another option if the situation warrants...

          Actually, most UI bindings don't (directly) use reflection: they use
          the component model [it just happens that the default component model
          implementation uses reflection].

          You could implement ICustomTypeDesc riptor, and return your own
          PropertyDescrip tor implementation (based for instance on
          SimplePropertyD escriptor IIRC).

          Again, it depends on the scenario - i.e. whether you need to hide
          properties based on the value of other properties... but it is a viable
          (and very powerful) alternative.

          Marc

          Comment

          Working...