locked
Why does EditorBrowsable not hide methods in Intellisense?

    Question

  • For Designer control, I am using the Resetxx() and ShouldSerializexx methods on some of my component class properties.  Since they are only to be used by the Designer, I naturally don't want them to clutter up my Intellisense dropdown for my class' members.  Hence I am decorating them with [EditorBrowsable(EditorBrowsableState.Never)] to hide them from the Intellisense.  But they still show up!!  I have seen in other posts that people are having problems with hiding items in the same Solution, but nowhere did I see an answer, and the latest post on those threads was 2006.  Has anyone found a solution to this?

    Wednesday, February 06, 2008 6:33 PM

Answers

  • Hi, Douglas

     

    This is by design. The designer does not hide those properties of the same solution. It won't hide them from you because you are the developer (of the solution) not the user (of the assembly).

     

    To get around this you need to reference to the assembly rather than the project. What I mean is that when you add a reference to a project in the same solution with an "Add reference" dialog, select the "Browse" tab and navigate the assembly(.exe, dll.) of that project.

     

    Best Regards

    Chunsheng Tang

    Friday, February 08, 2008 7:07 AM
    Moderator
  • Hi, I'm back here again to add a helpful hint.  I have discovered that the Resetxxx and ShouldSerializexxx methods can be marked protected, instead of public.  For some reason, although protected methods should only be accessible to child classes, the VS Properties Grid can nevertheless see and use them.  However, no other classes can, including those in your own project. 

    So the real answer to my question: Mark the Resetxxx and ShouldSerializexxx methods protected, instead of public.
    • Marked as answer by Douglas Hauck Friday, August 21, 2009 11:44 AM
    Friday, August 21, 2009 11:44 AM

All replies

  • Hi, Douglas

     

    This is by design. The designer does not hide those properties of the same solution. It won't hide them from you because you are the developer (of the solution) not the user (of the assembly).

     

    To get around this you need to reference to the assembly rather than the project. What I mean is that when you add a reference to a project in the same solution with an "Add reference" dialog, select the "Browse" tab and navigate the assembly(.exe, dll.) of that project.

     

    Best Regards

    Chunsheng Tang

    Friday, February 08, 2008 7:07 AM
    Moderator
  • Thank you.

    Friday, February 08, 2008 1:09 PM
  • Hi, I'm back here again to add a helpful hint.  I have discovered that the Resetxxx and ShouldSerializexxx methods can be marked protected, instead of public.  For some reason, although protected methods should only be accessible to child classes, the VS Properties Grid can nevertheless see and use them.  However, no other classes can, including those in your own project. 

    So the real answer to my question: Mark the Resetxxx and ShouldSerializexxx methods protected, instead of public.
    • Marked as answer by Douglas Hauck Friday, August 21, 2009 11:44 AM
    Friday, August 21, 2009 11:44 AM
  • The properties grid doesn't show methods, only properties.  It will show public properties only.  If you are seeing otherwise then please post the example code so we can take a look at it.

    EditorBrowsable doesn't impact the PG.  Instead PG reacts to the Browsable attribute.  If you don't want a property/event to show up then use this attribute and PG will ignore it.  The extreme other end is to write a custom property provider but that is generally overkill.

    Michael Taylor - 8/21/09
    http://p3net.mvps.org
    Friday, August 21, 2009 1:30 PM
    Moderator