如何在 IntelliSense 中隐藏公共方法 [英] How to hide public methods from IntelliSense

查看:22
本文介绍了如何在 IntelliSense 中隐藏公共方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 IntelliSense 成员列表中隐藏公共方法.我创建了一个属性,当应用于方法时,将导致在构造其对象时调用该方法.我这样做是为了更好地支持部分类.问题在于,在某些环境(例如 Silverlight)中,反射无法访问私有成员,甚至无法访问子类的私有成员.这是一个问题,因为所有的工作都是在一个基类中完成的.我必须公开这些方法,但我希望它们对 IntelliSense 隐藏,类似于 Obsolete 属性的工作方式.坦率地说,因为我对对象封装很感兴趣.我尝试了不同的东西,但实际上没有任何效果.该方法仍然显示在成员下拉列表中.

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.

当我不希望客户端调用公共方法时,如何防止公共方法出现在 IntelliSense 中?对于真正的问题,非利士人怎么办!这也适用于必须公开的 MEF 属性,但有时您想对客户端隐藏它们.

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.

推荐答案

扩展我对部分方法的评论.尝试这样的事情

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

Foo.part1.cs

Foo.part1.cs

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

    partial void Initialize();
}

Foo.part2.cs

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

这篇关于如何在 IntelliSense 中隐藏公共方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆