How to hide public methods from IntelliSense

前端 未结 3 1166
暖寄归人
暖寄归人 2020-11-29 04:44

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 obj

相关标签:
3条回答
  • 2020-11-29 04:49

    Using the EditorBrowsable attribute like so will cause a method not to be shown in IntelliSense:

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
    public void MyMethod()
    {
    }
    
    0 讨论(0)
  • 2020-11-29 04:50

    You are looking for EditorBrowsableAttribute

    The following sample demonstrates how to hide a property of a class from IntelliSense by setting the appropriate value for the EditorBrowsableAttribute attribute. Build Class1 in its own assembly.

    In Visual Studio, create a new Windows Application solution, and add a reference to the assembly which contains Class1. In the Form1 constructor, declare an instance of Class1, type the name of the instance, and press the period key to activate the IntelliSense drop-down list of Class1 members. The Age property does not appear in the drop-down list.

    using System;
    using System.ComponentModel;
    
    namespace EditorBrowsableDemo
    {
        public class Class1
        {
            public Class1()
            {
                //
                // TODO: Add constructor logic here
                //
            }
    
            int ageval;
    
            [EditorBrowsable(EditorBrowsableState.Never)]
            public int Age
            {
                get { return ageval; }
                set
                {
                    if (!ageval.Equals(value))
                    {
                        ageval = value;
                    }
                }
            }
        }
    }
    
    0 讨论(0)
  • 2020-11-29 04:54

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题