如何隐藏智能感知的公共方法智能、方法

2023-09-02 23:49:41 作者:北音執念

我要隐藏从智能感知成员列表公共方法。我已创建的属性,当用于一个方法将导致当它的对象被构​​造成调用的方法。我这样做,以更好地支持部分类。的问题是,在某些环境中(如Silverlight的),反射不能访问私有成员甚至这些子类。这是一个问题,因为所有的工作中,在碱类完成。我必须让这些方法公开,但我希望他们能够从智能感知隐藏,类似于如何使用过时属性的作品。坦率地说,因为我的肛门有关对象的封装。我已经尝试不同的东西,但一切都没有实际工作。该方法仍显示在成员下拉。

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 show up in the member drop-down.

如何防止公共方法不再出现在智能感知,当我不希望他们被称为客户端?是如何形成的一个的真正的问题,非利士人!这也适用于必须是公众虽然有时你想从客户端隐藏它们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
    }
}