从Visual Studio for C#的流畅接口类intellisense隐藏GetHashCode/Equals/ToString? [英] Hiding GetHashCode/Equals/ToString from fluent interface classes intellisense in Visual Studio for C#?

查看:136
本文介绍了从Visual Studio for C#的流畅接口类intellisense隐藏GetHashCode/Equals/ToString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个流畅的IoC容器注册过程接口,其中包含一些用于建立注册的类.

I have a fluent interface for an IoC container registration process, and this contains some classes that are used to build up the registrations.

例如,我可以这样做:

builder.Register<IFoo>().From.ConcreteType<Foo>();

但是,在点之后的每一步,都会弹出intellisense,显示Object类中的四个标准方法:GetHashCode,Equals,GetType和ToString.

However, at each step after a dot, intellisense pops up showing the four standard methods from the Object class, GetHashCode, Equals, GetType, and ToString.

我尝试在几个类中覆盖这些方法,并附加了 EditorBrowsableAttribute 属性,但它们仍会显示.我没有办法隐藏它们吗?

I tried overriding these methods in a couple of the classes, attaching the EditorBrowsableAttribute attribute to each, but they still show up. Is there no way for me to hide them?

请注意,我并不是在试图将它们隐藏在类本身中,而只是在智能感知中隐藏了它们.

Note that I'm not trying to hide them from the class itself, just from intellisense.

基本上,我想要这样:

                         +---------------+
builder.Register<IFoo>().|As             |
                         |By             |
                         |Equals         | <-- remove this
                         |From           |
                         |GetHashCode    | <-- and this
                         |GetType        | <-- as well as this
                         |ToString       | <-- and finally this
                         +---------------+

这是我在Register<T>返回的类中尝试过的内容:

Here's what I tried in the class that is returned from Register<T>:

[EditorBrowsable(EditorBrowsableState.Never)]
public override Boolean Equals(Object obj)
{
    return base.Equals(obj);
}

[EditorBrowsable(EditorBrowsableState.Never)]
public override Int32 GetHashCode()
{
    return base.GetHashCode();
}

[EditorBrowsable(EditorBrowsableState.Never)]
public override String ToString()
{
    return base.ToString();
}

这显然行不通.还有什么我可以尝试的吗?

This clearly did not work. Is there anything else I can try?

我还尝试添加一个新方法,该方法未从Object覆盖,并且对该属性应用了相同的属性,并且该属性也显示出来,因此很明显,该属性没有按照我的预期去做.

I also tried adding a new method, not overridden from Object, and applying the same attribute to that, and that too shows up, so clearly the attribute is not doing what I thought it would do.

我注意到文档中关于不在同一个程序集中隐藏内容的说明,但是我尝试创建一个新项目,但它们仍然显示在其中.

I noticed the note in the documentation about not hiding things from the same assembly, but I tried creating a new project and they still show up there.

推荐答案

根据

According to thread, it is by design. The methods/properties decorated with EditorBrowsable(EditorBrowsableState.Never) are only hidden from intellisense if they're part of a class that is in another referenced assembly. The assembly should not be part of the same solution.

这篇关于从Visual Studio for C#的流畅接口类intellisense隐藏GetHashCode/Equals/ToString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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