Search code examples
c#.netreflectionintellisenseencapsulation

How to hide public methods from IntelliSense


I want to hide public methods from the IntelliSense member list. I have created an attribute that, when applied to a method, will cause the method to be called when its object is constructed. I've done this to better support partial classes. The problem is that in some environments (such as Silverlight), reflection cannot access private members, even those of child classes. This is a problem since all of the work is done in a base class. I have to make these methods public, but I want them to be hidden from IntelliSense, similar to how the Obsolete attribute works. Frankly, because I am anal about object encapsulation. I've tried different things, but nothing has actually worked. The method still shows up in the member drop-down.

How do I keep public methods from showing up in IntelliSense when I don't want them to be called by clients? How's that for a real question, Philistines! This can also apply to MEF properties that have to be public though sometimes you want to hide them from clients.

Update: I have matured as a developer since I posted this question. Why I cared so much about hiding interface is beyond me.


Solution

  • To expand on my comment about partial methods. Try something like this

    Foo.part1.cs

    partial class Foo
    {
        public Foo()
        {
            Initialize();
        }
    
        partial void Initialize();
    }
    

    Foo.part2.cs

    partial class Foo
    {
        partial void Initialize()
        {
             InitializePart1();
             InitializePart2();
             InitializePart3();
        }
    
        private void InitializePart1()
        {
            //logic goes here
        }
    
        private void InitializePart2()
        {
            //logic goes here
        }
    
        private void InitializePart3()
        {
            //logic goes here
        }
    }