-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Performance.ImplementEqualsTypeRule(2.10)
Sebastien Pouliot edited this page Feb 18, 2011
·
4 revisions
Assembly: Gendarme.Rules.Performance
Version: 2.10
This rule looks for types that override Object.Equals(object) but do not provide a Equals(x) overload using the type. Such an overload removes the need to cast the object to the correct type. For value types this also removes the costly boxing operations. Assemblies targeting .NET 2.0 (and later) should also implement [[System.IEquatable<T>|http://msdn.microsoft.com/library/System.IEquatable.aspx]].
Bad example:
public class Bad {
public override bool Equals (object obj)
{
return base.Equals (obj);
}
public override int GetHashCode ()
{
return base.GetHashCode ();
}
}
Good example:
// IEquatable<T> is only available since
// version 2.0 of the .NET framework
public class Good : IEquatable<Good> {
public override bool Equals (object obj)
{
return (obj as Good);
}
public bool Equals (Good other)
{
return (other != null);
}
public override int GetHashCode ()
{
return base.GetHashCode ();
}
}
- This rule is available since Gendarme 2.0
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!