Since i installed resharper ( few days ago ), i enjoy using vs 2008 more. Not only it helps me to write fast code, it also teaches me better coding :)
You wonder how ? When i have a data representing class, i always overload ==,!=, Equals, GetHashCode() functions, such as:
public override string ToString()
{
return Name;
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
public override bool Equals(object obj)
{
if(obj == null)
return false;
Branch temp = (Branch) obj;
return temp.Name.ToLowerInvariant().Equals(this.Name.ToLowerInvariant());
}
public static bool operator==(Branch d1, Branch d2)
{
object o1 = (object) d1;
object o2 = (object) d2;
if( (o1== null) ||(o2==null))
return false;
return d1.Equals(d2);
}
public static bool operator !=(Branch d1, Branch d2)
{
return !(d1 == d2);
}
Today while i was doing the same thing for another class, right before i was going to overload, resharper's yellow icon poped up, i hit insert enter, and resharper asked me if i want to overload members, i click sure go ahead, here is the resharper code which is a lot smarter than mine:
public bool Equals(Counselor counselor)
{
if (counselor == null) return false;
return Equals(Email, counselor.Email);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj)) return true;
return Equals(obj as Counselor);
}
public override int GetHashCode()
{
return Email != null ? Email.GetHashCode() : 0;
}
Tags: resharper, c#