Wednesday, 17 February 2010

Hiding object methods from Visual Studio for Fluent Interfaces

To hide instance object methods your interface needs to inherit from:

[EditorBrowsable(EditorBrowsableState.Never)]
public interface IAmNotAnObject
{
[EditorBrowsable(EditorBrowsableState.Never)]
Type GetType();

[EditorBrowsable(EditorBrowsableState.Never)]
int GetHashCode();

[EditorBrowsable(EditorBrowsableState.Never)]
string ToString();

[EditorBrowsable(EditorBrowsableState.Never)]
bool Equals(object obj);
}

For static classes add the following code to your static classes:

#region Hide static object members
[EditorBrowsable(EditorBrowsableState.Never)]
public new static bool Equals(object objA, object objB)
{
return object.Equals(objA, objB);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public new static bool ReferenceEquals(object objA, object objB)
{
return object.ReferenceEquals(objA, objB);
}
#endregion