I have a fluent interface for an IoC container registration process, and this contains some classes that are used to build up the registrations.
For instance, I can do this:
builder.Register<IFoo>().From.ConcreteType<Foo>();
However, at each step after a dot, intellisense pops up showing the four standard methods from the Object class, GetHashCode, Equals, GetType, and ToString.
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.
Basically, I'd like this:
+---------------+
builder.Register<IFoo>().|As |
|By |
|Equals | <-- remove this
|From |
|GetHashCode | <-- and this
|GetType | <-- as well as this
|ToString | <-- and finally this
+---------------+
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?
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.
Ok, I found the solution, it was partly my fault, and partly incomplete documentation.
My fault was that I had not tagged all the methods in the correct class, but even when correcting that, the methods still showed up.
Turns out the note in the documentation, which reads:
In Visual C#, EditorBrowsableAttribute does not suppress members from a class in the same assembly.
Should actually be (emphasis mine):
In Visual C#, EditorBrowsableAttribute does not suppress members from a class in the same open solution.
I tagged the methods in the appropriate class, did a full rebuild, created a new project outside of the solution file, made file references to the compiled files from my IoC project, and lo and behold, the methods disappeared.
I'll leave the question up in case someone else has this problem.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With