Resharper is GREAT

by volkanuzun 3/21/2008 11:42:00 AM

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: ,

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

Volkan Uzun




E-mail me Send mail

Twitter

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Flickr Badge

www.flickr.com
This is a Flickr badge showing public photos from volkanuzun. Make your own badge here.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sign in